narval: add piuparts checker draft stable
authorJulien Cristau <julien.cristau@logilab.fr>
Wed, 18 Dec 2013 16:06:44 +0100
branchstable
changeset 1318 26d2b1b856b4
parent 923 478b60e0e112
child 1319 9ef256811ba1
narval: add piuparts checker Runs after lgp.build, and calls piuparts on all the changes files.
narval/apycot.py
--- a/narval/apycot.py	Mon Jun 10 16:55:21 2013 +0200
+++ b/narval/apycot.py	Wed Dec 18 16:06:44 2013 +0100
@@ -171,3 +171,92 @@
 
 apycotlib.register('checker', DebianLintianChecker)
 
+@input('changes-files', 'isinstance(elmt, FilePath)', 'elmt.type == "debian.changes"',
+       list=True)
+@apycotlib.apycotaction('piuparts', 'DEBIANPKG in elmt.done_steps')
+def act_piuparts(inputs):
+    test = inputs['apycot']
+    options = inputs['options'].copy()
+    options['changes-files'] = inputs['changes-files']
+    checker, status = test.run_checker('piuparts', options)
+    return {}
+
+class DebianPiupartsChecker(BaseChecker):
+    id = 'piuparts'
+
+    checked_extensions = ('.changes',)
+    options_def = {
+        'changes-files': {
+            'type': 'csv',
+            'required': True,
+            'help': 'changes files to check',
+        },
+        'extra-repos': {
+            'type': 'csv',
+            'required': False,
+            'help': 'extra repos to add to sources.list',
+        },
+    }
+
+    def __init__(self, *args, **kwargs):
+        super(DebianPiupartsChecker, self).__init__(*args, **kwargs)
+        self.basetgz = '/var/cache/lgp/buildd'
+        lgp_config = subprocess.Popen(['lgp', 'setup', '--dump-config'], stdout=subprocess.PIPE)
+        for line in lgp_config.stdout:
+            if line.startswith('basetgz='):
+                self.basetgz = line.split('=', 1)[1].strip()
+                break
+        if lgp_config.wait() != 0:
+            self.writer.error('could not get lgp config')
+        lgp_config.stdout.close()
+
+
+    def get_output(self, path, dist, arch):
+        basetgz = osp.join(self.basetgz, '%s-%s.tgz' % (dist, arch))
+        command = ['sudo', 'piuparts', '-b', basetgz, '-d', dist]
+        for extra_repo in self.options.get('extra-repos'):
+            command += ['--extra-repo', extra_repo]
+        command.append(path)
+        cmd = subprocess.Popen(command, stdout=subprocess.PIPE,
+                stdin=open('/dev/null'), stderr=subprocess.STDOUT)
+        output = []
+        for line in cmd.stdout:
+            if output and not line.startswith(' '):
+                yield output
+                output = []
+            output.append(line)
+        if output:
+            yield output
+        cmd.wait()
+
+    def do_check(self, test):
+        from debian.deb822 import Deb822
+
+        status = apycotlib.SUCCESS
+        for f in self.options.get('changes-files'):
+            with open(f.path) as changes :
+                archs = set(Deb822(changes)['Architecture'].split()) - set(('source', 'any', 'all'))
+            for arch in archs or ('amd64',):
+                iter_line = self.get_output(f.path, f.distribution, arch)
+                for lines in iter_line:
+                    msg = ''.join(lines)
+                    try:
+                        timestamp, mtype, _ = lines[0].split(None, 2)
+                    except ValueError:
+                        timestamp, mtype = lines[0].split(None, 2)
+                    if mtype == 'DEBUG:' or mtype == 'DUMP:':
+                        self.writer.debug(msg, path=f.path)
+                    elif mtype == 'ERROR:':
+                        self.writer.error(msg, path=f.path)
+                        status = apycotlib.FAILURE
+                    elif mtype == 'INFO:':
+                        self.writer.info(msg, path=f.path)
+                    else:
+                        self.writer.fatal('unexpected line %r' % msg, path=f.path)
+                        for lines in iter_line:
+                            self.writer.info('followed by: %r' % ''.join(lines), path=f.path)
+                        return apycotlib.ERROR
+        return status
+
+apycotlib.register('checker', DebianPiupartsChecker)
+