]> git.decadent.org.uk Git - dak.git/blob - daklib/lintian.py
Alter generate_reject_messages to return a generator.
[dak.git] / daklib / lintian.py
1 from regexes import re_parse_lintian
2
3 def parse_lintian_output(output):
4     """
5     Parses Lintian output and returns a generator with the data.
6
7     >>> list(parse_lintian_output('W: pkgname: some-tag path/to/file'))
8     [('W', 'pkgname', 'some-tag', 'path/to/file')]
9     """
10
11     for line in output.split('\n'):
12         m = re_parse_lintian.match(line)
13         if m:
14             yield m.groups()
15
16 def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args):
17     """
18     Generates package reject messages by comparing parsed lintian output with
19     tag definitions. Returns a generator containing the reject messages.
20     """
21
22     tags = set()
23     for values in tag_definitions.values():
24         for tag in values:
25             tags.add(tag)
26
27     for etype, epackage, etag, etext in parsed_tags:
28         if etag not in tags:
29             continue
30
31         # Was tag overridden?
32         if etype == 'O':
33
34             if etag in tag_definitions['nonfatal']:
35                 # Overriding this tag is allowed.
36                 pass
37
38             elif etag in tag_definitions['fatal']:
39                 # Overriding this tag is NOT allowed.
40
41                 log('ftpmaster does not allow tag to be overridable', etag)
42                 yield "%s: Overriden tag %s found, but this tag " \
43                     "may not be overridden." % (epackage, etag)
44
45         else:
46             # Tag is known and not overridden; reject
47             yield "%s: Found lintian output: '%s %s', automatically " \
48                 "rejected package." % (epackage, etag, etext)
49
50             # Now tell if they *might* override it.
51             if etag in tag_definitions['nonfatal']:
52                 log("auto rejecting", "overridable", etag)
53                 yield "%s: If you have a good reason, you may override this " \
54                    "lintian tag." % epackage
55             else:
56                 log("auto rejecting", "not overridable", etag)