]> git.decadent.org.uk Git - dak.git/blob - daklib/lintian.py
Add by-hash support
[dak.git] / daklib / lintian.py
1 #!/usr/bin/python
2
3 """ Utility functions for lintian checks in dak
4
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2009, 2010  Joerg Jaspert <joerg@debian.org>
7 @copyright: 2009  Chris Lamb <lamby@debian.org>
8 @license: GNU General Public License version 2 or later
9 """
10
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15
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.
20
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  USA
24
25 ################################################################################
26
27 # <mhy> I often wonder if we should use NSA bot or something instead and get dinstall
28 #       to send emails telling us about its progress :-)
29 # <mhy> dinstall: I'm processing openoffice
30 # <mhy> dinstall: I'm choking, please help me
31 # <Ganneff> yeah. get floods in here, for 600 accepted packages.
32 # <mhy> hehe
33 # <Ganneff> im not sure the other opers will like it if i oper up the bot, just so it
34 #           can flood faster
35 # <mhy> flood all debian related channels
36 # <mhy> just to be safe
37 # <Ganneff> /msg #debian-* dinstall: starting
38 # <Ganneff> more interesting would be the first message in #debian, the next in
39 #           #d-devel, then #d-qa
40 # <Ganneff> and expect people to monitor all.
41 # <Ganneff> i bet we have enough debian channels to at least put the timestamps in
42 #           seperate channels each
43 # <Ganneff> and if not  -  we can make it go multi-network
44 # <Ganneff> first oftc, then opn, then ircnet, then - we will find some. quakenet anyone?
45 # <mhy> I should know better than to give you ideas
46
47 ################################################################################
48
49 from regexes import re_parse_lintian
50
51 def parse_lintian_output(output):
52     """
53     Parses Lintian output and returns a generator with the data.
54
55     >>> list(parse_lintian_output('W: pkgname: some-tag path/to/file'))
56     [('W', 'pkgname', 'some-tag', 'path/to/file')]
57
58     @type output: string
59     @param output: The output from lintian
60     """
61
62     for line in output.split('\n'):
63         m = re_parse_lintian.match(line)
64         if m:
65             yield m.groupdict()
66
67 def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args):
68     """
69     Generates package reject messages by comparing parsed lintian output with
70     tag definitions. Returns a generator containing the reject messages.
71
72     @param parsed_tags: Parsed lintian tags as returned by L{parse_lintian_output}
73
74     @param tag_definitions: YAML.load lintian tag definitions to reject on
75
76     @return: Reject message(s), if any
77     """
78
79     tags = set()
80     for values in tag_definitions.values():
81         for tag_name in values:
82             tags.add(tag_name)
83
84     for tag in parsed_tags:
85         tag_name = tag['tag']
86
87         if tag_name not in tags:
88             continue
89
90         # Was tag overridden?
91         if tag['level'] == 'O':
92
93             if tag_name in tag_definitions['nonfatal']:
94                 # Overriding this tag is allowed.
95                 pass
96
97             elif tag_name in tag_definitions['fatal']:
98                 # Overriding this tag is NOT allowed.
99
100                 log('ftpmaster does not allow tag to be overridable', tag_name)
101                 yield "%(package)s: Overriden tag %(tag)s found, but this " \
102                     "tag may not be overridden." % tag
103
104         else:
105             # Tag is known and not overridden; reject
106             yield "%(package)s: lintian output: '%(tag)s %(description)s', " \
107                 "automatically rejected package." % tag
108
109             # Now tell if they *might* override it.
110             if tag_name in tag_definitions['nonfatal']:
111                 log("auto rejecting", "overridable", tag_name)
112                 yield "%(package)s: If you have a good reason, you may " \
113                    "override this lintian tag." % tag
114             else:
115                 log("auto rejecting", "not overridable", tag_name)