4 bts -- manage bugs filed against ftp.debian.org
6 Copyright 2009 Mike O'Connor <stew@vireo.org>
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the
11 # Free Software Foundation; either version 2, or (at your option) any
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24 ################################################################################
25 ################################################################################
30 log = logging.getLogger()
33 from daklib import utils
34 from btsutils.debbugs import debbugs
39 dak bts-categorize [options]
44 Don't send email, instead output the lines that would be sent to
49 Print more informational log messages
53 Suppress informational messages
57 Print this documentation.
60 arguments = [('s','simulate','BtsCategorize::Options::Simulate'),
61 ('v', 'verbose', 'BtsCategorize::Options::Verbose'),
62 ('q', 'quiet', 'BtsCategorize::Options::Quiet'),
63 ('h', 'help', 'BtsCategorize::Options::Help')]
65 class BugClassifier(object):
67 classify bugs using usertags based on the bug subject lines
69 >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
71 >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
73 >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
76 rm_re = re.compile( "^RM" )
77 dak_re = re.compile( "^\[dak\]" )
78 arch_re = re.compile( "^\[Architectures\]" )
80 classifiers = { rm_re: 'remove',
86 self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
89 def unclassified_bugs(self):
91 Returns a list of open bugs which have not yet been classified
92 by one of our usertags.
94 return [ bug for bug in self.bts.query("pkg:ftp.debian.org") \
95 if bug.status=='pending' and not bug.usertags ]
98 def classify_bug(self, bug):
100 if any of our classifiers match, return a newline terminated
101 command to set an appropriate usertag, otherwise return an
106 for classifier in self.classifiers.keys():
107 if classifier.match(bug.summary):
108 retval = "usertag %s %s\n" % (bug.bug,
109 self.classifiers[classifier])
115 log.debug("Unmatched: [%s] %s" % (bug.bug, bug.summary))
119 def email_text(self):
123 for bug in bc.unclassified_bugs():
124 controls += bc.classify_bug(bug)
128 def send_email(commands, simulate=False):
131 Subst = {'__COMMANDS__' : commands,
132 "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]}
134 bts_mail_message = utils.TemplateSubst(
135 Subst,Cnf["Dir::Templates"]+"/bts-categorize")
138 print bts_mail_message
140 utils.send_mail( bts_mail_message )
144 for now, we just dump a list of commands that could be sent for
148 Cnf = utils.get_conf()
150 for arg in arguments:
151 opt = "BtsCategorize::Options::%s" % arg[1]
152 if not Cnf.has_key(opt):
155 packages = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
156 Options = Cnf.SubTree('BtsCategorize::Options')
165 elif Options["Verbose"]:
171 logging.basicConfig( level=level,
172 format='%(asctime)s %(levelname)s %(message)s',
173 stream = sys.stderr )
175 body = BugClassifier().email_text()
178 send_email(body, Options["Simulate"])
181 log.info( "nothing to do" )
184 if __name__ == '__main__':