From: Chris Lamb Date: Sat, 31 Oct 2009 10:54:29 +0000 (+0000) Subject: Make daklib.lintian work on the named groups, not the "flat" groups X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bebf929c1fb775e07157a0d2f4bbedb82e0eabcc;p=dak Make daklib.lintian work on the named groups, not the "flat" groups Signed-off-by: Chris Lamb --- diff --git a/daklib/lintian.py b/daklib/lintian.py index 8e65d3f5..3d1afc80 100644 --- a/daklib/lintian.py +++ b/daklib/lintian.py @@ -11,7 +11,7 @@ def parse_lintian_output(output): for line in output.split('\n'): m = re_parse_lintian.match(line) if m: - yield m.groups() + yield m.groupdict() def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args): """ @@ -21,36 +21,38 @@ def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: arg tags = set() for values in tag_definitions.values(): - for tag in values: - tags.add(tag) + for tag_name in values: + tags.add(tag_name) - for etype, epackage, etag, etext in parsed_tags: - if etag not in tags: + for tag in parsed_tags: + tag_name = tag['tag'] + + if tag_name not in tags: continue # Was tag overridden? - if etype == 'O': + if tag['level'] == 'O': - if etag in tag_definitions['nonfatal']: + if tag_name in tag_definitions['nonfatal']: # Overriding this tag is allowed. pass - elif etag in tag_definitions['fatal']: + elif tag_name in tag_definitions['fatal']: # Overriding this tag is NOT allowed. - log('ftpmaster does not allow tag to be overridable', etag) - yield "%s: Overriden tag %s found, but this tag " \ - "may not be overridden." % (epackage, etag) + log('ftpmaster does not allow tag to be overridable', tag_name) + yield "%(package)s: Overriden tag %(tag)s found, but this " \ + "tag may not be overridden." % tag else: # Tag is known and not overridden; reject - yield "%s: Found lintian output: '%s %s', automatically " \ - "rejected package." % (epackage, etag, etext) + yield "%(package)s: lintian output: '%(tag)s %(description)s', " \ + "automatically rejected package." % tag # Now tell if they *might* override it. - if etag in tag_definitions['nonfatal']: - log("auto rejecting", "overridable", etag) - yield "%s: If you have a good reason, you may override this " \ - "lintian tag." % epackage + if tag_name in tag_definitions['nonfatal']: + log("auto rejecting", "overridable", tag_name) + yield "%(package)s: If you have a good reason, you may " \ + "override this lintian tag." % tag else: - log("auto rejecting", "not overridable", etag) + log("auto rejecting", "not overridable", tag_name) diff --git a/tests/test_lintian.py b/tests/test_lintian.py index 4a574a9d..f4ed98ef 100755 --- a/tests/test_lintian.py +++ b/tests/test_lintian.py @@ -15,8 +15,12 @@ class ParseLintianTestCase(DakTestCase): def testSimple(self): self.assertParse( - 'W: pkgname: some-tag path/to/file', - [('W', 'pkgname', 'some-tag', 'path/to/file')], + 'W: pkgname: some-tag path/to/file', [{ + 'level': 'W', + 'package': 'pkgname', + 'tag': 'some-tag', + 'description': 'path/to/file', + }], ) self.assertParse('', []) @@ -25,20 +29,32 @@ class ParseLintianTestCase(DakTestCase): def testBinaryNoDescription(self): self.assertParse( - 'W: pkgname: some-tag', - [('W', 'pkgname', 'some-tag', '')], + 'W: pkgname: some-tag', [{ + 'level': 'W', + 'package': 'pkgname', + 'tag': 'some-tag', + 'description': '', + }], ) def testSource(self): self.assertParse( - 'W: pkgname source: some-tag', - [('W', 'pkgname source', 'some-tag', '')] + 'W: pkgname source: some-tag', [{ + 'level': 'W', + 'package': 'pkgname source', + 'tag': 'some-tag', + 'description': '', + }] ) def testSourceNoDescription(self): self.assertParse( - 'W: pkgname source: some-tag path/to/file', - [('W', 'pkgname source', 'some-tag', 'path/to/file')] + 'W: pkgname source: some-tag path/to/file', [{ + 'level': 'W', + 'package': 'pkgname source', + 'tag': 'some-tag', + 'description': 'path/to/file', + }] ) class GenerateRejectMessages(DakTestCase): @@ -47,51 +63,84 @@ class GenerateRejectMessages(DakTestCase): self.assertEqual(len(msgs), num) def testUnknownTag(self): - self.assertNumReject( - [('W', 'pkgname', 'unknown-tag', '')], - {'fatal': ['known-tag'], 'nonfatal': []}, + self.assertNumReject([ + { + 'level': 'W', + 'package': 'pkgname', + 'tag': 'unknown-tag', + 'description': '', + } + ], {'fatal': ['known-tag'], 'nonfatal': []}, 0, ) def testFatalTags(self): self.assertNumReject([ - ('W', 'pkgname', 'fatal-tag-1', ''), - ('W', 'pkgname', 'fatal-tag-2', ''), - ], - {'fatal': ['fatal-tag-1', 'fatal-tag-2'], 'nonfatal': []}, + { + 'level': 'W', + 'package': 'pkgname', + 'tag': 'fatal-tag-1', + 'description': '', + }, + { + 'level': 'W', + 'package': 'pkgname', + 'tag': 'fatal-tag-2', + 'description': '', + }, + ], {'fatal': ['fatal-tag-1', 'fatal-tag-2'], 'nonfatal': []}, 2, ) def testMixture(self): self.assertNumReject([ - ('W', 'pkgname', 'fatal-tag', ''), - ('W', 'pkgname', 'unknown-tag', ''), - ], - {'fatal': ['fatal-tag'], 'nonfatal': []}, + { + 'level': 'W', + 'package': 'pkgname', + 'tag': 'fatal-tag', + 'description': '', + }, + { + 'level': 'W', + 'package': 'pkgname', + 'tag': 'unknown-tag', + 'description': '', + }, + ], {'fatal': ['fatal-tag'], 'nonfatal': []}, 1, ) def testOverridable(self): self.assertNumReject([ - ('W', 'pkgname', 'non-fatal-tag', ''), - ], - {'fatal': [], 'nonfatal': ['non-fatal-tag']}, + { + 'level': 'W', + 'package': 'pkgname', + 'tag': 'non-fatal-tag', + 'description': '', + }, + ], {'fatal': [], 'nonfatal': ['non-fatal-tag']}, 1 + 1, # We add an extra 'reject' hint message ) def testOverrideAllowed(self): self.assertNumReject([ - ('O', 'pkgname', 'non-fatal-tag', ''), - ], - {'fatal': [], 'nonfatal': ['non-fatal-tag']}, + {'level': 'O', + 'package': 'pkgname', + 'tag': 'non-fatal-tag', + 'description': ''}, + ], {'fatal': [], 'nonfatal': ['non-fatal-tag']}, 0, ) def testOverrideNotAllowed(self): self.assertNumReject([ - ('O', 'pkgname', 'fatal-tag', ''), - ], - {'fatal': ['fatal-tag'], 'nonfatal': []}, + { + 'level': 'O', + 'package': 'pkgname', + 'tag': 'fatal-tag', + 'description': '', + }, + ], {'fatal': ['fatal-tag'], 'nonfatal': []}, 1, )