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 @copyright: 2010 Alexander Reichle-Schmehl <tolimar@debian.org>
9 @license: GNU General Public License version 2 or later
12 # This program is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation; either version 2, or (at your option) any
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 ################################################################################
28 ################################################################################
33 log = logging.getLogger()
36 from daklib import utils
37 import debianbts as bts
42 dak bts-categorize [options]
47 Don't send email, instead output the lines that would be sent to
52 Print more informational log messages
56 Suppress informational messages
60 Print this documentation.
63 arguments = [('s','simulate','BtsCategorize::Options::Simulate'),
64 ('v', 'verbose', 'BtsCategorize::Options::Verbose'),
65 ('q', 'quiet', 'BtsCategorize::Options::Quiet'),
66 ('h', 'help', 'BtsCategorize::Options::Help')]
68 class BugClassifier(object):
70 classify bugs using usertags based on the bug subject lines
72 >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
74 >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
76 >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
79 rm_re = re.compile( "^RM" )
80 dak_re = re.compile( "^\[dak\]" )
81 arch_re = re.compile( "^\[Architectures\]" )
82 override_re = re.compile( "^override" )
84 classifiers = { rm_re: 'remove',
87 override_re: 'override'}
89 def unclassified_bugs(self):
91 Returns a list of open bugs which have not yet been classified
92 by one of our usertags.
95 tagged_bugs = bts.get_usertag('ftp.debian.org@packages.debian.org')
97 for tags in tagged_bugs.keys():
98 tagged_bugs_ftp += tagged_bugs[tags]
100 return [ bug for bug in bts.get_status( bts.get_bugs("package", "ftp.debian.org" ) ) \
101 if bug.pending=='pending' and not bug.bug_num in tagged_bugs_ftp ]
104 def classify_bug(self, bug):
106 if any of our classifiers match, return a newline terminated
107 command to set an appropriate usertag, otherwise return an
112 for classifier in self.classifiers.keys():
113 if classifier.match(bug.subject):
114 retval = "usertag %s %s\n" % (bug.bug_num,
115 self.classifiers[classifier])
121 log.debug("Unmatched: [%s] %s" % (bug.bug_num, bug.subject))
125 def email_text(self):
130 for bug in bc.unclassified_bugs():
131 controls += bc.classify_bug(bug)
135 log.error("couldn't retrieve bugs from soap interface: %s" % sys.exc_info()[0])
138 def send_email(commands, simulate=False):
141 Subst = {'__COMMANDS__' : commands,
142 "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]}
144 bts_mail_message = utils.TemplateSubst(
145 Subst,Cnf["Dir::Templates"]+"/bts-categorize")
148 print bts_mail_message
150 utils.send_mail( bts_mail_message )
154 for now, we just dump a list of commands that could be sent for
158 Cnf = utils.get_conf()
160 for arg in arguments:
161 opt = "BtsCategorize::Options::%s" % arg[1]
162 if not Cnf.has_key(opt):
165 packages = apt_pkg.parse_commandline(Cnf, arguments, sys.argv)
166 Options = Cnf.subtree('BtsCategorize::Options')
175 elif Options["Verbose"]:
181 logging.basicConfig( level=level,
182 format='%(asctime)s %(levelname)s %(message)s',
183 stream = sys.stderr )
185 body = BugClassifier().email_text()
188 send_email(body, Options["Simulate"])
191 log.info( "nothing to do" )
194 if __name__ == '__main__':