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
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
###############################################################################
# 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
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):
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):
[('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()