[Piuparts-commits] [piuparts] 10/12: p-a: process all sections

Holger Levsen holger at layer-acht.org
Wed Oct 11 14:58:45 UTC 2017


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

holger pushed a commit to branch develop
in repository piuparts.

commit 1137eb8ef0b45490d7c4a3711a4fbe278f425ffc
Author: Andreas Beckmann <anbe at debian.org>
Date:   Wed Oct 4 05:24:34 2017 +0200

    p-a: process all sections
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
    Signed-off-by: Holger Levsen <holger at layer-acht.org>
---
 debian/changelog                           |  2 ++
 master-bin/report_newly_bugged_packages.in |  3 ++
 piuparts-analyze.py                        | 55 +++++++++++++++++++++++++++---
 3 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 5b33a39..f950f55 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,8 @@ piuparts (0.83) UNRELEASED; urgency=medium
     - Use test_versions() in all places referring to a piuparts test.
     - Set test_versions while loading versions from the final target distro.
     - Use the actual package versions for resolving the "outdated" state.
+  * piuparts-analyze.py:
+    - Merge report_newly_bugged_packages and process all sections.
   * piuparts-report.py, detect_well_known_errors.py, piuparts-analyze.py:
     - Use global locks to allow only one running instance of each script.
     - Acquire section locks to prevent concurrent processing of a section,
diff --git a/master-bin/report_newly_bugged_packages.in b/master-bin/report_newly_bugged_packages.in
index 3ffd9c1..63c484d 100644
--- a/master-bin/report_newly_bugged_packages.in
+++ b/master-bin/report_newly_bugged_packages.in
@@ -24,6 +24,9 @@ get_config_value PYTHONPATH global PYTHONPATH ''
 get_config_value DEBEMAIL global bts-from ''
 
 
+ at sharedir@/piuparts/piuparts-analyze 2>&1
+exit 0
+
 export PYTHONPATH
 
 OLDPWD=$(pwd)
diff --git a/piuparts-analyze.py b/piuparts-analyze.py
index 9844674..281d83b 100644
--- a/piuparts-analyze.py
+++ b/piuparts-analyze.py
@@ -33,6 +33,7 @@ move the failed log to ./bugged as well.
 
 import os
 import sys
+import time
 import re
 import shutil
 import subprocess
@@ -42,6 +43,12 @@ import debianbts
 import apt_pkg
 from signal import alarm, signal, SIGALRM
 
+import piupartslib.conf
+from piupartslib.conf import MissingSection
+
+
+CONFIG_FILE = "/etc/piuparts/piuparts.conf"
+
 apt_pkg.init_system()
 
 error_pattern = re.compile(r"(?<=\n).*error.*\n?", flags=re.IGNORECASE)
@@ -127,6 +134,17 @@ piupartsbts = PiupartsBTS()
 
 ############################################################################
 
+class Config(piupartslib.conf.Config):
+    def __init__(self, section="global", defaults_section=None):
+        self.section = section
+        piupartslib.conf.Config.__init__(self, section,
+                                         {
+                                         "sections": "report",
+                                         "master-directory": ".",
+                                         },
+                                         defaults_section=defaults_section)
+
+
 def find_logs(directory):
     """Returns list of logfiles sorted by age, newest first."""
     logs = [os.path.join(directory, x)
@@ -291,12 +309,41 @@ def mark_logs_with_reported_bugs():
 
 
 def main():
-    with open("master.lock", "we") as lock:
-        fcntl.flock(lock, fcntl.LOCK_EX)
+    conf = Config()
+    conf.read(CONFIG_FILE)
+
+    master_directory = conf["master-directory"]
+    if len(sys.argv) > 1:
+        sections = sys.argv[1:]
+    else:
+        sections = conf['sections'].split()
 
-        mark_logs_with_reported_bugs()
+    with open(os.path.join(master_directory, "analyze.lock"), "we") as lock:
+        try:
+            fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        except IOError:
+            sys.exit("another piuparts-analyze process is already running")
 
-    piupartsbts.print_stats()
+        for section_name in sections:
+            print(time.strftime("%a %b %2d %H:%M:%S %Z %Y", time.localtime()))
+            print("%s:" % section_name)
+            try:
+                section_directory = os.path.join(master_directory, section_name)
+                if not os.path.exists(section_directory):
+                    raise MissingSection("", section_name)
+                with open(os.path.join(section_directory, "master.lock"), "we") as lock:
+                    fcntl.flock(lock, fcntl.LOCK_EX)
+
+                    oldcwd = os.getcwd()
+                    os.chdir(section_directory)
+                    mark_logs_with_reported_bugs()
+                    os.chdir(oldcwd)
+            except MissingSection as e:
+                print("Configuration Error in section '%s': %s" % (section_name, e))
+            print("")
+
+        print(time.strftime("%a %b %2d %H:%M:%S %Z %Y", time.localtime()))
+        piupartsbts.print_stats()
 
 
 if __name__ == "__main__":

-- 
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