From bd2f59abe3833efd703db5e075c8ce67f0b7864a Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Sat, 31 Oct 2009 10:03:19 +0000 Subject: [PATCH] Generate lintian reject messages in daklib.lintian + tests Signed-off-by: Chris Lamb --- daklib/lintian.py | 46 ++++++++++++++++++++++++++++++++++++ daklib/queue.py | 39 +++++++----------------------- tests/test_lintian.py | 55 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 32 deletions(-) diff --git a/daklib/lintian.py b/daklib/lintian.py index c0ee316a..32c63db0 100644 --- a/daklib/lintian.py +++ b/daklib/lintian.py @@ -12,3 +12,49 @@ def parse_lintian_output(output): m = re_parse_lintian.match(line) if m: yield m.groups() + +def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args): + rejects = [] + + tags = set() + for values in tag_definitions.values(): + for tag in values: + tags.add(tag) + + for etype, epackage, etag, etext in parsed_tags: + if etag not in tags: + continue + + # Was tag overridden? + if etype == 'O': + + if etag in tag_definitions['nonfatal']: + # Overriding this tag is allowed. + pass + + elif etag in tag_definitions['fatal']: + # Overriding this tag is NOT allowed. + + log('ftpmaster does not allow tag to be overridable', etag) + rejects.append( + "%s: Overriden tag %s found, but this tag " + "may not be overridden." % (epackage, etag) + ) + + else: + # Tag is known and not overridden; reject + rejects.append( + "%s: Found lintian output: '%s %s', automatically " + "rejected package." % (epackage, etag, etext) + ) + + # Now tell if they *might* override it. + if etag in tag_definitions['nonfatal']: + log("auto rejecting", "overridable", etag) + rejects.append( + "%s: If you have a good reason, you may override this " + "lintian tag." % epackage) + else: + log("auto rejecting", "not overridable", etag) + + return rejects diff --git a/daklib/queue.py b/daklib/queue.py index f52fe363..bb66b2fd 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -54,7 +54,7 @@ from summarystats import SummaryStats from utils import parse_changes, check_dsc_files from textutils import fix_maintainer from binary import Binary -from lintian import parse_lintian_output +from lintian import parse_lintian_output, generate_reject_messages ############################################################################### @@ -1287,14 +1287,11 @@ class Upload(object): # through lintians output later to see if its a fatal tag we detected, or not. # So we only run lintian once on all tags, even if we might reject on some, but not # reject on others. - # Additionally build up a set of tags - tags = set() (fd, temp_filename) = utils.temp_filename() temptagfile = os.fdopen(fd, 'w') - for tagtype in lintiantags: - for tag in lintiantags[tagtype]: + for tags in lintiantags.values(): + for tag in tags: temptagfile.write("%s\n" % tag) - tags.add(tag) temptagfile.close() # So now we should look at running lintian at the .changes file, capturing output @@ -1311,35 +1308,15 @@ class Upload(object): utils.warn("lintian failed for %s [return code: %s]." % (self.pkg.changes_file, result)) utils.warn(utils.prefix_multi_line_string(output, " [possible output:] ")) + parsed_tags = parse_lintian_output(output) + def log(*txt): if self.logger: self.logger.log([self.pkg.changes_file, "check_lintian"] + list(txt)) - for etype, epackage, etag, etext in parse_lintian_output(output): - - # So lets check if we know the tag at all. - if etag not in tags: - continue - - if etype == 'O': - # We know it and it is overriden. Check that override is allowed. - if etag in lintiantags['nonfatal']: - # The tag is overriden, and it is allowed to be overriden. - # Don't add a reject message. - pass - elif etag in lintiantags['fatal']: - # The tag is overriden - but is not allowed to be - self.rejects.append("%s: Overriden tag %s found, but this tag may not be overwritten." % (epackage, etag)) - log("ftpmaster does not allow tag to be overridable", etag) - else: - # Tag is known, it is not overriden, direct reject. - self.rejects.append("%s: Found lintian output: '%s %s', automatically rejected package." % (epackage, etag, etext)) - # Now tell if they *might* override it. - if etag in lintiantags['nonfatal']: - log("auto rejecting", "overridable", etag) - self.rejects.append("%s: If you have a good reason, you may override this lintian tag." % (epackage)) - else: - log("auto rejecting", "not overridable", etag) + self.rejects.extend( + generate_reject_messages(parsed_tags, lintiantags, log=log) + ) ########################################################################### def check_urgency(self): diff --git a/tests/test_lintian.py b/tests/test_lintian.py index 99d5e93a..27d13680 100755 --- a/tests/test_lintian.py +++ b/tests/test_lintian.py @@ -4,7 +4,7 @@ from base_test import DakTestCase import unittest -from daklib.lintian import parse_lintian_output +from daklib.lintian import parse_lintian_output, generate_reject_messages class ParseLintianTestCase(DakTestCase): def assertParse(self, output, expected): @@ -41,5 +41,58 @@ class ParseLintianTestCase(DakTestCase): [('W', 'pkgname source', 'some-tag', 'path/to/file')] ) +class GenerateRejectMessages(DakTestCase): + def assertNumReject(self, input, defs, num): + self.assertEqual(len(generate_reject_messages(input, defs)), num) + + def testUnknownTag(self): + self.assertNumReject( + [('W', 'pkgname', 'unknown-tag', '')], + {'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': []}, + 2, + ) + + def testMixture(self): + self.assertNumReject([ + ('W', 'pkgname', 'fatal-tag', ''), + ('W', 'pkgname', 'unknown-tag', ''), + ], + {'fatal': ['fatal-tag'], 'nonfatal': []}, + 1, + ) + + def testOverridable(self): + self.assertNumReject([ + ('W', 'pkgname', 'non-fatal-tag', ''), + ], + {'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']}, + 0, + ) + + def testOverrideNotAllowed(self): + self.assertNumReject([ + ('O', 'pkgname', 'fatal-tag', ''), + ], + {'fatal': ['fatal-tag'], 'nonfatal': []}, + 1, + ) + if __name__ == '__main__': unittest.main() -- 2.39.5