]> git.decadent.org.uk Git - dak.git/commitdiff
Merge commit 'stew/categorize-bts' into merge
authorJoerg Jaspert <joerg@debian.org>
Sun, 25 Jan 2009 16:51:40 +0000 (17:51 +0100)
committerJoerg Jaspert <joerg@debian.org>
Sun, 25 Jan 2009 16:51:40 +0000 (17:51 +0100)
* commit 'stew/categorize-bts':
  git rid of useless email realeted imports.  added docstring for module
  Use dak's facility for sending email.  Add bts-categorize to cron.dinstall
  dont send email unless there is something to categorize
  move bts_categorize into dak, send email
  drop logging level
  a script that categorizes bugs against ftp.debian.org

Signed-off-by: Joerg Jaspert <joerg@debian.org>
config/debian/cron.dinstall
dak/bts_categorize.py [new file with mode: 0755]
dak/dak.py
templates/bts-categorize [new file with mode: 0644]

index 403a03fdf96c4d61a5e0a96eb7b1ac7acb4eaa0a..afa2571074eb82bb34e752380a3cb592b9126006 100755 (executable)
@@ -256,6 +256,9 @@ ts "reports"
 echo "Updating DM html page"
 $scriptsdir/dm-monitor >$webdir/dm-uploaders.html
 
+echo "Categorizing uncategorized bugs filed against ftp.debian.org"
+dak bts-categorize
+
 ################################################################################
 
 # Push katie@merkel so it syncs the projectb there. Returns immediately, the sync runs detached
diff --git a/dak/bts_categorize.py b/dak/bts_categorize.py
new file mode 100755 (executable)
index 0000000..9112178
--- /dev/null
@@ -0,0 +1,187 @@
+#!/usr/bin/python
+
+"""
+bts -- manage bugs filed against ftp.debian.org
+
+Copyright 2009 Mike O'Connor <stew@vireo.org>
+"""
+
+#  This program is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU General Public License as published by the
+#  Free Software Foundation; either version 2, or (at your option) any
+#  later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+#  USA.
+
+################################################################################
+################################################################################
+
+import sys
+import re
+import logging
+log = logging.getLogger()
+
+import apt_pkg
+from daklib import utils
+from btsutils.debbugs import debbugs
+
+def usage():
+    print """
+SYNOPSIS
+    dak bts-categorize [options]
+
+OPTIONS
+    -s
+    --simulate
+        Don't send email, instead output the lines that would be sent to
+        control@b.d.o.
+
+    -v
+    --verbose
+        Print more informational log messages
+
+    -q
+    --quiet
+        Suppress informational messages
+
+    -h
+    --help
+        Print this documentation.
+"""
+
+arguments = [('s','simulate','BtsCategorize::Options::Simulate'),
+             ('v', 'verbose', 'BtsCategorize::Options::Verbose'),
+             ('q', 'quiet', 'BtsCategorize::Options::Quiet'),
+             ('h', 'help', 'BtsCategorize::Options::Help')]
+
+class BugClassifier(object):
+    """
+    classify bugs using usertags based on the bug subject lines
+
+    >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
+    True
+    >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
+    False
+    >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
+    True
+    """
+    rm_re = re.compile( "^RM" )
+    dak_re = re.compile( "^\[dak\]" )
+    arch_re = re.compile( "^\[Architectures\]" )
+
+    classifiers = { rm_re: 'remove',
+                    dak_re: 'dak',
+                    arch_re: 'archs'}
+
+    def __init__( self ):
+        self.bts = debbugs()
+        self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
+
+
+    def unclassified_bugs(self):
+        """
+        Returns a list of open bugs which have not yet been classified
+        by one of our usertags.
+        """
+        return [ bug for bug in self.bts.query("pkg:ftp.debian.org") \
+                     if bug.status=='pending' and not bug.usertags ]
+
+
+    def classify_bug(self, bug):
+        """
+        if any of our classifiers match, return a newline terminated
+        command to set an appropriate usertag, otherwise return an
+        empty string
+        """
+        retval = ""
+
+        for classifier in self.classifiers.keys():
+            if classifier.match(bug.summary):
+                retval = "usertag %s %s\n" % (bug.bug,
+                                            self.classifiers[classifier])
+                break
+
+        if retval:
+            log.info(retval)
+        else:
+            log.debug("Unmatched: [%s] %s" % (bug.bug, bug.summary))
+
+        return retval
+
+    def email_text(self):
+        controls = ""
+
+        bc = BugClassifier()
+        for bug in bc.unclassified_bugs():
+            controls += bc.classify_bug(bug)
+
+        return controls
+
+def send_email(commands, simulate=False):
+    global Cnf
+
+    Subst = {'__COMMANDS__' : commands,
+             "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]}
+
+    bts_mail_message = utils.TemplateSubst(
+        Subst,Cnf["Dir::Templates"]+"/bts-categorize")
+
+    if simulate:
+        print bts_mail_message
+    else:
+        utils.send_mail( bts_mail_message )
+
+def main():
+    """
+    for now, we just dump a list of commands that could be sent for
+    control@b.d.o
+    """
+    global Cnf
+    Cnf = utils.get_conf()
+
+    for arg in arguments:
+        opt = "BtsCategorize::Options::%s" % arg[1]
+        if not Cnf.has_key(opt):
+            Cnf[opt] = ""
+
+    packages = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
+    Options = Cnf.SubTree('BtsCategorize::Options')
+
+    if Options["Help"]:
+        usage()
+        sys.exit( 0 )
+
+    if Options["Quiet"]:
+        level=logging.ERROR
+
+    elif Options["Verbose"]:
+        level=logging.DEBUG
+
+    else:
+        level=logging.INFO
+
+    logging.basicConfig( level=level,
+                         format='%(asctime)s %(levelname)s %(message)s',
+                         stream = sys.stderr )
+
+    body = BugClassifier().email_text()
+
+    if body:
+        send_email(body, Options["Simulate"])
+
+    else:
+        log.info( "nothing to do" )
+
+
+if __name__ == '__main__':
+#    import doctest
+#    doctest.testmod()
+    main()
index ad717ef3959f2aecf52166d6336287623e0d5126..dc7aa1e373a630584b81a95d8797c0d07824bb71 100755 (executable)
@@ -162,6 +162,8 @@ def init():
          "Split queue/done into a date-based hierarchy"),
         ("stats",
          "Generate statistics"),
+        ("bts-categorize",
+         "Categorize uncategorized bugs filed against ftp.debian.org"),
         ]
     return functionality
 
diff --git a/templates/bts-categorize b/templates/bts-categorize
new file mode 100644 (file)
index 0000000..7f43e1a
--- /dev/null
@@ -0,0 +1,6 @@
+From: __DAK_ADDRESS__
+To: control@bugs.debian.org
+X-Debian: DAK
+
+user ftp.debian.org@packages.debian.org
+__COMMANDS__