4 bts -- manage bugs filed against ftp.debian.org
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009 Mike O'Connor <stew@vireo.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the
13 # Free Software Foundation; either version 2, or (at your option) any
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 ################################################################################
27 ################################################################################
32 log = logging.getLogger()
35 from daklib import utils
36 from btsutils.debbugs import debbugs
41 dak bts-categorize [options]
46 Don't send email, instead output the lines that would be sent to
51 Print more informational log messages
55 Suppress informational messages
59 Print this documentation.
62 arguments = [('s','simulate','BtsCategorize::Options::Simulate'),
63 ('v', 'verbose', 'BtsCategorize::Options::Verbose'),
64 ('q', 'quiet', 'BtsCategorize::Options::Quiet'),
65 ('h', 'help', 'BtsCategorize::Options::Help')]
67 class BugClassifier(object):
69 classify bugs using usertags based on the bug subject lines
71 >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
73 >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
75 >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
78 rm_re = re.compile( "^RM" )
79 dak_re = re.compile( "^\[dak\]" )
80 arch_re = re.compile( "^\[Architectures\]" )
82 classifiers = { rm_re: 'remove',
88 self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
91 def unclassified_bugs(self):
93 Returns a list of open bugs which have not yet been classified
94 by one of our usertags.
96 return [ bug for bug in self.bts.query("pkg:ftp.debian.org") \
97 if bug.status=='pending' and not bug.usertags ]
100 def classify_bug(self, bug):
102 if any of our classifiers match, return a newline terminated
103 command to set an appropriate usertag, otherwise return an
108 for classifier in self.classifiers.keys():
109 if classifier.match(bug.summary):
110 retval = "usertag %s %s\n" % (bug.bug,
111 self.classifiers[classifier])
117 log.debug("Unmatched: [%s] %s" % (bug.bug, bug.summary))
121 def email_text(self):
126 for bug in bc.unclassified_bugs():
127 controls += bc.classify_bug(bug)
131 log.error("couldn't retrieve bugs from soap interface: %s" % sys.exc_info()[0])
134 def send_email(commands, simulate=False):
137 Subst = {'__COMMANDS__' : commands,
138 "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]}
140 bts_mail_message = utils.TemplateSubst(
141 Subst,Cnf["Dir::Templates"]+"/bts-categorize")
144 print bts_mail_message
146 utils.send_mail( bts_mail_message )
150 for now, we just dump a list of commands that could be sent for
154 Cnf = utils.get_conf()
156 for arg in arguments:
157 opt = "BtsCategorize::Options::%s" % arg[1]
158 if not Cnf.has_key(opt):
161 packages = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
162 Options = Cnf.SubTree('BtsCategorize::Options')
171 elif Options["Verbose"]:
177 logging.basicConfig( level=level,
178 format='%(asctime)s %(levelname)s %(message)s',
179 stream = sys.stderr )
181 body = BugClassifier().email_text()
184 send_email(body, Options["Simulate"])
187 log.info( "nothing to do" )
190 if __name__ == '__main__':