]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/lintian.py
Generate lintian reject messages in daklib.lintian + tests
[dak.git] / daklib / lintian.py
index c0ee316a6e4a172e7690fd7a9991e73b04afe0ab..32c63db0d2e3199f41650b66444e6a2767a300ad 100644 (file)
@@ -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