[Piuparts-commits] [piuparts] 07/09: p-r: import the reporting part from dwke

Holger Levsen holger at moszumanska.debian.org
Mon Feb 10 13:03:04 UTC 2014


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

holger pushed a commit to branch develop
in repository piuparts.

commit cdaa76351508b2ed923444a5d6e8891891e931c0
Author: Andreas Beckmann <anbe at debian.org>
Date:   Sun Feb 9 18:09:55 2014 +0100

    p-r: import the reporting part from dwke
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
---
 piuparts-report.py | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)

diff --git a/piuparts-report.py b/piuparts-report.py
index 42b36f5..80e3bee 100644
--- a/piuparts-report.py
+++ b/piuparts-report.py
@@ -4,6 +4,7 @@
 # Copyright 2005 Lars Wirzenius (liw at iki.fi)
 # Copyright 2009-2013 Holger Levsen (holger at layer-acht.org)
 # Copyright © 2011-2014 Andreas Beckmann (anbe at debian.org)
+# Copyright 2013 David Steele (dsteele at gmail.com)
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the
@@ -50,6 +51,8 @@ from piupartslib.conf import MissingSection
 
 CONFIG_FILE = "/etc/piuparts/piuparts.conf"
 DISTRO_CONFIG_FILE = "/etc/piuparts/distros.conf"
+KPR_DIRS = ('pass', 'bugged', 'affected', 'fail')
+TPL_EXT = '.tpl'
 
 
 PIUPARTS_VERSION = "__PIUPARTS_VERSION__"
@@ -342,6 +345,39 @@ ANALYSIS_BODY_TEMPLATE = """
    </table>
 """
 
+PROB_TPL = \
+"""<tr class="titlerow"><td class="titlecell">
+$HEADER in $SECTION, sorted by reverse dependency count.
+</td></tr><tr class="normalrow"><td class="contentcell2">
+$HELPTEXT
+<p>The commandline to find these logs is: <pre>
+COMMAND='$COMMAND'
+</pre></p>
+</td></tr><tr class="titlerow"><td class="alerttitlecell">Please file bugs!</td></tr><tr class="normalrow"><td class="contentcell2" colspan="3">
+<ul>
+$PACKAGE_LIST</ul>
+<p>Affected packages in $SECTION: $COUNT</p></td></tr>
+"""
+
+UNKNOWN_TPL = \
+"""<tr class="titlerow"><td class="titlecell">
+Packages with unknown failures detected in $SECTION, sorted by reverse dependency count.
+</td></tr><tr class="normalrow"><td class="contentcell2">
+<p>Please investigate and improve detection of known error types!</p>
+</td></tr><tr class="titlerow"><td class="alerttitlecell">Please file bugs!</td></tr><tr class="normalrow"><td class="contentcell2" colspan="3">
+<ul>
+$PACKAGE_LIST
+</ul>
+<p>Affected packages in $SECTION: $COUNT</p></td></tr>
+"""
+
+PKG_ERROR_TPL = \
+"""<li>$RDEPS - <a href=\"$LOG\">$LOG</a>
+    (<a href=\"http://packages.qa.debian.org/$SDIR/$SPKG.html\" target=\"_blank\">PTS</a>)
+    (<a href=\"http://bugs.debian.org/$PACKAGE?dist=unstable\" target=\"_blank\">BTS</a>)
+$BUG</li>
+"""
+
 
 title_by_dir = {
     "pass": "PASSED piuparts logs",
@@ -1423,6 +1459,138 @@ class Section:
         os.chdir(oldcwd)
 
 
+# START detect_well_known_errors
+
+def pts_subdir(source):
+    if source[:3] == "lib":
+        return source[:4]
+    else:
+        return source[:1]
+
+def source_pkg(pkgspec, db):
+    source_name = db.get_control_header(get_pkg(pkgspec), "Source")
+
+    return source_name
+
+def get_pkgspec(logpath):
+    """For a log full file spec, return the pkgspec (<pkg>_<version)"""
+    return logpath.split('/')[-1]
+
+def get_bug_text(logpath):
+    bugpath = replace_ext(logpath, BUG_EXT)
+
+    txt = ""
+    if os.path.exists(bugpath):
+        bf = open(bugpath, 'r')
+        txt = bf.read()
+        bf.close()
+
+    return txt
+
+def section_path(logpath):
+    """Convert a full log path name to one relative to the section directory"""
+    return '/'.join([get_where(logpath), get_pkgspec(logpath)])
+
+def populate_tpl(tmpl, vals):
+
+    for key in vals:
+        tmpl = re.sub("\$%s" % key, str(vals[key]), tmpl)
+
+    return tmpl
+
+def update_tpl(basedir, section, problem, failures, logdict, ftpl, ptpl, pkgsdb):
+
+    pkg_text = ""
+    bugged_section = False
+    for failure in failures:
+
+        pkgspec = failure.pkgspec
+        bin_pkg = get_pkg(pkgspec)
+        rdep_cnt = pkgsdb.rrdep_count(bin_pkg)
+        pkg_obj = pkgsdb.get_package(bin_pkg)
+
+        if not pkg_obj is None:
+            src_pkg = source_pkg(pkgspec, pkgsdb)
+        else:
+            src_pkg = bin_pkg
+
+        if bugged_section is False and get_where(logdict[pkgspec]) != 'fail':
+            bugged_section = True
+            pkg_text += "</ul><ul>\n"
+
+        pkg_text += populate_tpl(ftpl, {
+                                'LOG': section_path(logdict[pkgspec]),
+                                'PACKAGE': bin_pkg,
+                                'BUG': get_bug_text(logdict[pkgspec]),
+                                'RDEPS': rdep_cnt,
+                                'SDIR':pts_subdir(src_pkg),
+                                'SPKG':src_pkg,
+                                   })
+
+    if len(pkg_text):
+        pf = open(os.path.join(basedir, failures[0].problem[:-5] + TPL_EXT), 'w')
+        tpl_text = populate_tpl(ptpl, {
+                                'HEADER': problem.HEADER,
+                                'SECTION': section,
+                                'HELPTEXT': problem.HELPTEXT,
+                                'COMMAND': problem.get_command(),
+                                'PACKAGE_LIST': pkg_text,
+                                'COUNT': len(failures),
+                                })
+
+        pf.write(tpl_text)
+        pf.close()
+
+def update_html(section, logdict, problem_list, failures, config, pkgsdb):
+
+    html_dir = os.path.join(config['output-directory'], section)
+    if not os.path.exists(html_dir):
+        os.makedirs(html_dir)
+
+    for problem in problem_list:
+        update_tpl(html_dir, section, problem,
+                   failures.filtered(problem.name),
+                   logdict,
+                   PKG_ERROR_TPL, PROB_TPL, pkgsdb)
+
+    # Make a failure list of all failed packages that don't show up as known
+    failedpkgs = set([x for x in logdict.keys()
+                     if get_where(logdict[x]) != 'pass'])
+    knownfailpkgs = set([failure.pkgspec for failure in failures.failures])
+    unknownsasfailures = [make_failure("", "unknown_failures.conf", x)
+                         for x in failedpkgs.difference(knownfailpkgs)]
+
+    def keyfunc(x, pkgsdb=pkgsdb, logdict=logdict):
+        rdeps = pkgsdb.rrdep_count(get_pkg(x.pkgspec))
+
+        is_failed = get_where(logdict[x.pkgspec]) == "fail"
+
+        return (not is_failed, -rdeps, logdict[x.pkgspec])
+
+    unknownsasfailures.sort(key=keyfunc)
+
+    update_tpl(html_dir, section, problem_list[0], unknownsasfailures,
+               logdict,
+               PKG_ERROR_TPL, UNKNOWN_TPL, pkgsdb)
+
+def process_section(section, config, problem_list,
+                    recheck=False, recheck_failed=False, pkgsdb=None):
+
+    sectiondir = os.path.join(config['master-directory'], section)
+    workdirs = [os.path.join(sectiondir, x) for x in KPR_DIRS]
+
+    [os.mkdir(x) for x in workdirs if not os.path.exists(x)]
+
+    logdict = get_file_dict(workdirs, LOG_EXT)
+
+    failures = FailureManager(logdict)
+    failures.sort_by_bugged_and_rdeps(pkgsdb)
+
+    update_html(section, logdict, problem_list, failures, config, pkgsdb)
+
+# END detect_well_known_errors
+
+
 def main():
     setup_logging(logging.DEBUG, None)
     global_config = Config(section="global")

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



More information about the Piuparts-commits mailing list