3 # bts -- manage bugs filed against ftp.debian.org
5 # Copyright 2009 Mike O'Connor <stew@vireo.org>
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2, or (at your option) any
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 ################################################################################
23 ################################################################################
28 log = logging.getLogger()
31 from daklib import utils
32 from btsutils.debbugs import debbugs
37 dak bts-categorize [options]
42 Don't send email, instead output the lines that would be sent to
47 Print more informational log messages
51 Suppress informational messages
55 Print this documentation.
58 arguments = [('s','simulate','BtsCategorize::Options::Simulate'),
59 ('v', 'verbose', 'BtsCategorize::Options::Verbose'),
60 ('q', 'quiet', 'BtsCategorize::Options::Quiet'),
61 ('h', 'help', 'BtsCategorize::Options::Help')]
63 class BugClassifier(object):
65 classify bugs using usertags based on the bug subject lines
67 >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
69 >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
71 >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
74 rm_re = re.compile( "^RM" )
75 dak_re = re.compile( "^\[dak\]" )
76 arch_re = re.compile( "^\[Architectures\]" )
78 classifiers = { rm_re: 'remove',
84 self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
87 def unclassified_bugs(self):
89 Returns a list of open bugs which have not yet been classified
90 by one of our usertags.
92 return [ bug for bug in self.bts.query("pkg:ftp.debian.org") \
93 if bug.status=='pending' and not bug.usertags ]
96 def classify_bug(self, bug):
98 if any of our classifiers match, return a newline terminated
99 command to set an appropriate usertag, otherwise return an
104 for classifier in self.classifiers.keys():
105 if classifier.match(bug.summary):
106 retval = "usertag %s %s\n" % (bug.bug,
107 self.classifiers[classifier])
113 log.debug("Unmatched: [%s] %s" % (bug.bug, bug.summary))
117 def email_text(self):
121 for bug in bc.unclassified_bugs():
122 controls += bc.classify_bug(bug)
129 def send_email(commands, simulate):
132 Subst = {'__COMMANDS__' : commands,
133 "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]}
135 bts_mail_message = utils.TemplateSubst(
136 Subst,Cnf["Dir::Templates"]+"/bts-categorize")
139 print bts_mail_message
141 utils.send_mail( bts_mail_message )
145 for now, we just dump a list of commands that could be sent for
149 Cnf = utils.get_conf()
151 for arg in arguments:
152 opt = "BtsCategorize::Options::%s" % arg[1]
153 if not Cnf.has_key(opt):
156 packages = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
157 Options = Cnf.SubTree('BtsCategorize::Options')
166 elif Options["Verbose"]:
172 logging.basicConfig( level=level,
173 format='%(asctime)s %(levelname)s %(message)s',
174 stream = sys.stderr )
176 body = BugClassifier().email_text()
179 send_email(body, Options["Simulate"])
182 log.info( "nothing to do" )
185 if __name__ == '__main__':