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 dak bts-categorize [options] command
32 List the currently defind categorizations for bugs
35 Find the bugs filed against ftp.debian.org which have no usertag
36 and see if we can categorize the bug by adding a usertag by matching
37 the subject against a list of regexps.
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')]
66 log = logging.getLogger()
69 from daklib import utils
70 from btsutils.debbugs import debbugs
72 class BugClassifier(object):
74 classify bugs using usertags based on the bug subject lines
76 >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
78 >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
80 >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
83 rm_re = re.compile( "^RM" )
84 dak_re = re.compile( "^\[dak\]" )
85 arch_re = re.compile( "^\[Architectures\]" )
87 classifiers = { rm_re: 'remove',
93 self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
96 def unclassified_bugs(self):
98 Returns a list of open bugs which have not yet been classified
99 by one of our usertags.
101 return [ bug for bug in self.bts.query("pkg:ftp.debian.org") \
102 if bug.status=='pending' and not bug.usertags ]
105 def classify_bug(self, bug):
107 if any of our classifiers match, return a newline terminated
108 command to set an appropriate usertag, otherwise return an
113 for classifier in self.classifiers.keys():
114 if classifier.match(bug.summary):
115 retval = "usertag %s %s\n" % (bug.bug,
116 self.classifiers[classifier])
122 log.debug("Unmatched: [%s] %s" % (bug.bug, bug.summary))
126 def email_text(self):
127 controls = 'user ftp.debian.org@packages.debian.org\n'
130 for bug in bc.unclassified_bugs():
131 controls += bc.classify_bug(bug)
139 def send_email(body):
140 to = 'control@bugs.debian.org'
141 sender = 'ak@ries.debian.org'
142 message = email.Message.Message()
144 message["From"] = sender
145 message.set_payload(body)
146 mailServer = smtplib.SMTP('localhost')
147 mailServer.sendmail(sender, to, message.as_string())
152 for now, we just dump a list of commands that could be sent for
156 Cnf = utils.get_conf()
158 for arg in arguments:
159 opt = "BtsCategorize::Options::%s" % arg[1]
160 if not Cnf.has_key(opt):
163 packages = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
164 Options = Cnf.SubTree('BtsCategorize::Options')
173 elif Options["Verbose"]:
179 logging.basicConfig( level=level,
180 format='%(asctime)s %(levelname)s %(message)s',
181 stream = sys.stderr )
183 body = BugClassifier().email_text()
185 if Options["Simulate"]:
192 if __name__ == '__main__':