]> git.decadent.org.uk Git - dak.git/blob - daklib/lintian.py
Generate lintian reject messages in daklib.lintian + tests
[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     rejects = []
18
19     tags = set()
20     for values in tag_definitions.values():
21         for tag in values:
22             tags.add(tag)
23
24     for etype, epackage, etag, etext in parsed_tags:
25         if etag not in tags:
26             continue
27
28         # Was tag overridden?
29         if etype == 'O':
30
31             if etag in tag_definitions['nonfatal']:
32                 # Overriding this tag is allowed.
33                 pass
34
35             elif etag in tag_definitions['fatal']:
36                 # Overriding this tag is NOT allowed.
37
38                 log('ftpmaster does not allow tag to be overridable', etag)
39                 rejects.append(
40                     "%s: Overriden tag %s found, but this tag "
41                     "may not be overridden." % (epackage, etag)
42                 )
43
44         else:
45             # Tag is known and not overridden; reject
46             rejects.append(
47                 "%s: Found lintian output: '%s %s', automatically "
48                 "rejected package." % (epackage, etag, etext)
49             )
50
51             # Now tell if they *might* override it.
52             if etag in tag_definitions['nonfatal']:
53                 log("auto rejecting", "overridable", etag)
54                 rejects.append(
55                     "%s: If you have a good reason, you may override this "
56                     "lintian tag." % epackage)
57             else:
58                 log("auto rejecting", "not overridable", etag)
59
60     return rejects