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\]" )
83 classifiers = { rm_re: 'remove',
88 # Tolimar: I'm not really sure, what the following line used to to
89 # with btsutils, but I think it's not needed any more with
91 # self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
94 def unclassified_bugs(self):
96 Returns a list of open bugs which have not yet been classified
97 by one of our usertags.
100 tagged_bugs = bts.get_usertag('ftp.debian.org@packages.debian.org')
102 for tags in tagged_bugs.keys():
103 tagged_bugs_ftp += tagged_bugs[tags]
105 return [ bug for bug in bts.get_status( bts.get_bugs("package", "ftp.debian.org" ) ) \
106 if bug.pending=='pending' and not bug.bug_num in tagged_bugs_ftp ]
109 def classify_bug(self, bug):
111 if any of our classifiers match, return a newline terminated
112 command to set an appropriate usertag, otherwise return an
117 for classifier in self.classifiers.keys():
118 if classifier.match(bug.summary):
119 retval = "usertag %s %s\n" % (bug.bug_num,
120 self.classifiers[classifier])
126 log.debug("Unmatched: [%s] %s" % (bug.bug_num, bug.summary))
130 def email_text(self):
135 for bug in bc.unclassified_bugs():
136 controls += bc.classify_bug(bug)
140 log.error("couldn't retrieve bugs from soap interface: %s" % sys.exc_info()[0])
143 def send_email(commands, simulate=False):
146 Subst = {'__COMMANDS__' : commands,
147 "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]}
149 bts_mail_message = utils.TemplateSubst(
150 Subst,Cnf["Dir::Templates"]+"/bts-categorize")
153 print bts_mail_message
155 utils.send_mail( bts_mail_message )
159 for now, we just dump a list of commands that could be sent for
163 Cnf = utils.get_conf()
165 for arg in arguments:
166 opt = "BtsCategorize::Options::%s" % arg[1]
167 if not Cnf.has_key(opt):
170 packages = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
171 Options = Cnf.SubTree('BtsCategorize::Options')
180 elif Options["Verbose"]:
186 logging.basicConfig( level=level,
187 format='%(asctime)s %(levelname)s %(message)s',
188 stream = sys.stderr )
190 body = BugClassifier().email_text()
193 send_email(body, Options["Simulate"])
196 log.info( "nothing to do" )
199 if __name__ == '__main__':