]> git.decadent.org.uk Git - dak.git/blob - scripts/debian/bts-categorize
a script that categorizes bugs against ftp.debian.org
[dak.git] / scripts / debian / bts-categorize
1 #!/usr/bin/python
2
3 #  categorize-bts -- categorize
4 #
5 #  Copyright 2009 Mike O'Connor <stew@vireo.org>
6 #  
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
10 #  later version.
11 #  
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.
16 #  
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,
20 #  USA.  
21
22 import sys
23 import re
24 import logging
25 log = logging.getLogger()
26
27 from btsutils.debbugs import debbugs
28
29 class BugClassifier(object):
30     """
31     classify bugs using usertags based on the bug subject lines
32
33     >>> BugClassifier.rm_re.match( "RM: asdf" ) != None
34     True
35     >>> BugClassifier.rm_re.match( "[dak] Packages.diff/Index broken" ) != None
36     False
37     >>> BugClassifier.dak_re.match( "[dak] Packages.diff/Index broken" ) != None
38     True
39     """
40     rm_re = re.compile( "^RM" )
41     dak_re = re.compile( "^\[dak\]" )
42     classifiers = { rm_re: 'remove',
43                     dak_re: "dak" }
44
45     def __init__( self ):
46
47         self.bts = debbugs()
48         self.bts.setUsers(['ftp.debian.org@packages.debian.org'])
49
50             
51     def unclassified_bugs(self):
52         """
53         Returns a list of bugs which have not yet been classified by one
54         of our usertags.
55         """
56         return [ bug for bug in self.bts.query("pkg:ftp.debian.org") \
57                      if bug.status=='pending' and not bug.usertags ]
58
59
60     def classify_bug(self, bug):
61         """
62         if any of our classifiers match, return a newline terminated
63         command to set an appropriate usertag, otherwise return an
64         empty string
65         """
66         retval = ""
67
68         for classifier in self.classifiers.keys():
69             if classifier.match(bug.summary):
70                 retval = "usertag %s %s\n" % (bug.bug, 
71                                             self.classifiers[classifier])
72                 break
73
74         log.debug( retval )
75         return retval 
76
77
78 def main():
79     """
80     for now, we just dump a list of commands that could be sent for
81     control@b.d.o
82     """
83
84     level=logging.INFO
85     level=logging.DEBUG
86
87     logging.basicConfig( level=level,
88                          format='%(asctime)s %(levelname)s %(message)s',
89                          stream = sys.stderr )
90
91     controls = "user ftp.debian.org@packages.debian.org\n"
92
93     bc = BugClassifier()
94     for bug in bc.unclassified_bugs():
95         controls += bc.classify_bug(bug)
96
97     print controls
98
99
100 if __name__ == "__main__":
101 #    import doctest
102 #    doctest.testmod()
103     main()