[apycotlib] add back lintian checker (closes #2925088)
authorPaul Tonelli <paul.tonelli@logilab.fr>
Fri, 22 Nov 2013 16:30:06 +0100
changeset 1432 71952d5c0bfd
parent 1431 b5c8a94aba19
child 1433 6c8893df6244
[apycotlib] add back lintian checker (closes #2925088)
_apycotlib/checkers/debian.py
_apycotlib/narvalactions.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/_apycotlib/checkers/debian.py	Fri Nov 22 16:30:06 2013 +0100
@@ -0,0 +1,68 @@
+import apycotlib
+import logging
+import os
+import subprocess
+from apycotlib.checkers import BaseChecker
+
+def find_with_extension(path, extension):
+    path = os.path.expanduser(path)
+    for folder, subfolders, files in os.walk(path):
+        for filename in files:
+            if filename.endswith(extension):
+                yield os.path.join(folder, filename)
+
+class DebianLintianChecker(BaseChecker):
+    """Runs the lintian program after building a debian package. Lintian
+    checks for bugs and debian policy violations."""
+
+    id = 'lintian'
+
+    checked_extensions = ('.changes',)
+    options_def = {
+        'changes-files': {
+            'type': 'csv',
+            'required': False,
+            'help': 'changes files to check',
+        },
+    }
+
+    def get_output(self, path):
+        cmd = subprocess.Popen(['lintian', '-I', '--suppress-tags',
+                                'bad-distribution-in-changes-file', path],
+                               stdout=subprocess.PIPE, stdin=open('/dev/null'),
+                               stderr=subprocess.STDOUT)
+        for line in cmd.stdout:
+            yield line
+        cmd.wait()
+
+    def do_check(self, test):
+        status = apycotlib.SUCCESS
+        build_folder = os.path.join(test.project_path(), os.pardir)
+        change_files = find_with_extension(build_folder, '.changes')
+        if not change_files:
+            status = apycotlib.NODATA
+        for f in change_files:
+            iter_line = self.get_output(f)
+            for line in iter_line:
+                line_parts = line.split(':', 1)
+                try:
+                    mtype, msg = line_parts
+                except ValueError:
+                    self.writer.fatal('unexpected line %r' % line, path=f)
+                    for line in iter_line:
+                        self.writer.info('followed by: %r' % line, path=f)
+                    return apycotlib.ERROR
+                else:
+                    if mtype == 'I':
+                        self.writer.info(msg, path=f)
+                    elif mtype == 'W':
+                        self.writer.warning(msg, path=f)
+                    elif mtype == 'E':
+                        self.writer.error(msg, path=f)
+                        status = apycotlib.FAILURE
+                    else:
+                        self.writer.info(msg, path=f)
+        return status
+
+apycotlib.register('checker', DebianLintianChecker)
+
--- a/_apycotlib/narvalactions.py	Fri Apr 25 14:50:06 2014 +0200
+++ b/_apycotlib/narvalactions.py	Fri Nov 22 16:30:06 2013 +0100
@@ -1,6 +1,6 @@
 from apycotlib import atest, writer, ERROR
 from apycotlib import preprocessors # trigger registration
-from apycotlib.checkers import python, scenarios # trigger registration
+from apycotlib.checkers import python, debian, scenarios # trigger registration
 
 class apycot_environment(object):
     def __init__(self, plan):