[Pkg-debile-commits] [debile-slave] 52/100: add lintian bits

Sylvestre Ledru sylvestre at alioth.debian.org
Mon Aug 19 14:53:07 UTC 2013


This is an automated email from the git hooks/post-receive script.

sylvestre pushed a commit to branch master
in repository debile-slave.

commit e19f6b565cbb9189205363a090e21489ed1c98e8
Author: Paul Tagliamonte <tag at pault.ag>
Date:   Fri May 31 19:28:45 2013 -0400

    add lintian bits
---
 ethel/commands/__init__.py              |    5 ++++
 ethel/commands/build.py                 |    8 ++++++-
 ethel/commands/desktop_file_validate.py |    8 +++++++
 ethel/commands/lintian.py               |    7 ++++++
 ethel/commands/lintian4py.py            |    7 ++++++
 ethel/daemon.py                         |    7 +++---
 ethel/runners/desktop_file_validate.py  |   17 ++++++++++++++
 ethel/runners/lintian.py                |   19 +++++++++++++++
 ethel/runners/sbuild.py                 |    2 +-
 ethel/utils.py                          |    2 +-
 ethel/wrappers/lintian.py               |   39 +++++++++++++++++++++++++++++++
 tests/wrappers/test_lintian.py          |   15 ++++++++++++
 12 files changed, 130 insertions(+), 6 deletions(-)

diff --git a/ethel/commands/__init__.py b/ethel/commands/__init__.py
index 0d20b81..5094afe 100644
--- a/ethel/commands/__init__.py
+++ b/ethel/commands/__init__.py
@@ -3,8 +3,13 @@ import importlib
 
 PLUGINS = {
     "build": "ethel.commands.build",
+
+    "lintian": "ethel.commands.lintian",
+    "lintian4py": "ethel.commands.lintian4py",
+
     "adequate": "ethel.commands.adequate",
     "piuparts": "ethel.commands.piuparts",
+    "desktop-file-validate": "ethel.commands.desktop_file_validate",
 }
 
 
diff --git a/ethel/commands/build.py b/ethel/commands/build.py
index a8d69b2..9762f68 100644
--- a/ethel/commands/build.py
+++ b/ethel/commands/build.py
@@ -1,5 +1,6 @@
 from ethel.runners.sbuild import sbuild
 from ethel.utils import upload
+import os
 
 
 # target package firehose
@@ -14,5 +15,10 @@ def run(dsc, package, job, firehose):
         version=package['version'],
         arch=arch)
 
-    upload(changes, job['_id'])
+    if os.path.exists(changes):
+        upload(changes, job['_id'])
+    elif not ftbfs:
+        print(out)
+        raise Exception("Um. No changes but no FTBFS.")
+
     return (info, out, ftbfs)
diff --git a/ethel/commands/desktop_file_validate.py b/ethel/commands/desktop_file_validate.py
new file mode 100644
index 0000000..6d50eaf
--- /dev/null
+++ b/ethel/commands/desktop_file_validate.py
@@ -0,0 +1,8 @@
+from ethel.runners.desktop_file_validate import desktop_file_validate
+from ethel.utils import run_command, cd
+
+
+def run(dsc, source, job, firehose):
+    run_command(["dpkg-source", "-x", dsc, "source"])
+    with cd('source'):
+        return desktop_file_validate('source', firehose)
diff --git a/ethel/commands/lintian.py b/ethel/commands/lintian.py
new file mode 100644
index 0000000..dddcb37
--- /dev/null
+++ b/ethel/commands/lintian.py
@@ -0,0 +1,7 @@
+from ethel.runners.lintian import lintian
+
+
+def run(dfiles, package, job, firehose):
+    if not isinstance(dfiles, list):
+        dfiles = [dfiles]
+    return lintian(dfiles, firehose, lintian_binary='lintian')
diff --git a/ethel/commands/lintian4py.py b/ethel/commands/lintian4py.py
new file mode 100644
index 0000000..6736279
--- /dev/null
+++ b/ethel/commands/lintian4py.py
@@ -0,0 +1,7 @@
+from ethel.runners.lintian import lintian
+
+
+def run(dfiles, package, job, firehose):
+    if not isinstance(dfiles, list):
+        dfiles = [dfiles]
+    return lintian(dfiles, firehose, lintian_binary='lintian4py')
diff --git a/ethel/daemon.py b/ethel/daemon.py
index 85d3e36..f80b54d 100644
--- a/ethel/daemon.py
+++ b/ethel/daemon.py
@@ -102,12 +102,13 @@ def iterate():
                              "binaries": "binary"}[package['_type']]
 
                     print("[ethel] - filing report")
-                    proxy.submit_report(firehose, log, job['_id'], err)
+                    proxy.submit_report(firehose.to_json(),
+                                        log, job['_id'], err)
 
 def main():
     while True:
         try:
             iterate()
         except IDidNothingError:
-            print("[ethel] nothing to do.")
-            time.sleep(10)
+            #print("[ethel] nothing to do.")
+            time.sleep(30)
diff --git a/ethel/runners/desktop_file_validate.py b/ethel/runners/desktop_file_validate.py
new file mode 100644
index 0000000..58b3096
--- /dev/null
+++ b/ethel/runners/desktop_file_validate.py
@@ -0,0 +1,17 @@
+from ethel.wrappers.desktop_file_validate import parse_desktop_file_validate
+from ethel.utils import run_command
+import os
+
+
+def desktop_file_validate(package_root, analysis):
+    log = ""
+    failed = False
+    for dirpath, dirnames, filenames in os.walk(package_root):
+        for fp in filenames:
+            out, err, ret = run_command(['desktop-file-validate', fp])
+            for issue in parse_desktop_file_validate(out.splitlines()):
+                analysis.results.append(issue)
+                failed = True
+            log += out
+    log = log.strip()
+    return (analysis, log, failed)
diff --git a/ethel/runners/lintian.py b/ethel/runners/lintian.py
new file mode 100644
index 0000000..5054bcb
--- /dev/null
+++ b/ethel/runners/lintian.py
@@ -0,0 +1,19 @@
+from ethel.wrappers.lintian import parse_lintian
+from ethel.utils import run_command
+import os
+
+
+def lintian(packages, analysis, lintian_binary='lintian'):
+    log = ""
+    failed = False
+
+    for package in packages:
+        out, err, ret = run_command([lintian_binary, "-IE", "--pedantic",
+                                     "--show-overrides", package])
+        for issue in parse_lintian(out.splitlines(), package):
+            analysis.results.append(issue)
+            if issue.severity in ['warning', 'error']:
+                failed = True
+        log += out
+
+    return (analysis, log, failed)
diff --git a/ethel/runners/sbuild.py b/ethel/runners/sbuild.py
index cb45494..91daa7c 100644
--- a/ethel/runners/sbuild.py
+++ b/ethel/runners/sbuild.py
@@ -69,6 +69,7 @@ def sbuild(package, dist, arch):
 
     out, err, ret = run_command([
         "sbuild",
+        "-A",
         "-c", chroot,
         "-v",
         "-d", dist,
@@ -76,7 +77,6 @@ def sbuild(package, dist, arch):
         package,
     ])
     ftbfs = ret != 0
-    out, err = out.decode('utf-8'), err.decode('utf-8')
     info = parse_sbuild_log(out, sut=sut)
 
     return info, out, ftbfs
diff --git a/ethel/utils.py b/ethel/utils.py
index d385b45..6be9221 100644
--- a/ethel/utils.py
+++ b/ethel/utils.py
@@ -44,6 +44,7 @@ def run_command(command, stdin=None):
         kwargs['input'] = stdin.read()
 
     (output, stderr) = pipe.communicate(**kwargs)
+    output, stderr = (c.decode('utf-8') for c in (output, stderr))
     return (output, stderr, pipe.returncode)
 
 
@@ -52,7 +53,6 @@ def safe_run(cmd, expected=0):
         expected = (expected, )
 
     out, err, ret = run_command(cmd)
-    out, err = (x.decode('utf-8') for x in (out, err))
 
     if not ret in expected:
         e = EthelSubprocessError(out, err, ret, cmd)
diff --git a/ethel/wrappers/__init__.py b/ethel/wrappers/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/ethel/wrappers/lintian.py b/ethel/wrappers/lintian.py
new file mode 100644
index 0000000..d79be87
--- /dev/null
+++ b/ethel/wrappers/lintian.py
@@ -0,0 +1,39 @@
+from firehose.model import Issue, Message, File, Location, Point
+import re
+
+
+LINE_RE = re.compile(
+    r"(?P<severity>.*): (?P<package>.*): (?P<testid>[^\s]+)( (?P<message>.*))?"
+)
+
+def parse_lintian(lines, fpath):
+    severities = {
+        "w": "warning",
+        "e": "error",
+        "p": "pedantic",
+        "i": "info",
+        "x": "experimental",
+        "o": "override",
+    }
+
+    for line in lines:
+        if line.startswith("N:"):
+            continue
+
+        info = LINE_RE.match(line).groupdict()
+        severity = info['severity'].lower()
+
+        if severity in severities:
+            severity = severities[severity]
+        else:
+            severity = severity.upper()
+
+        yield Issue(cwe=None,
+                    testid=info['testid'],
+                    location=Location(file=File(fpath, None),
+                                      function=None,
+                                      point=None),
+                    severity=severity,
+                    message=Message(text=line),
+                    notes=None,
+                    trace=None)
diff --git a/tests/wrappers/test_lintian.py b/tests/wrappers/test_lintian.py
new file mode 100644
index 0000000..b613be3
--- /dev/null
+++ b/tests/wrappers/test_lintian.py
@@ -0,0 +1,15 @@
+from ethel.wrappers.lintian import parse_lintian
+
+
+TESTS = [
+    ("W: dput-ng source: newer-standards-version 3.9.4 (current is 3.9.3)",
+        "warning"),
+    ("I: dput-ng: package-contains-empty-directory usr/share/dput-ng/metas/",
+        "info"),
+]
+
+
+def test_lintian():
+    for string, tid in TESTS:
+        issue = next(parse_lintian([string], 'what'))
+        assert issue.severity == tid

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-debile/debile-slave.git



More information about the Pkg-debile-commits mailing list