[Piuparts-commits] [piuparts] 02/06: piuparts-report.py: Refactor global summary

Holger Levsen holger at moszumanska.debian.org
Sat Jun 21 12:28:31 UTC 2014


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

holger pushed a commit to branch submission
in repository piuparts.

commit 64615858e8a8021e593a22649fac0656e116fb5b
Author: David Steele <dsteele at gmail.com>
Date:   Sun Apr 27 14:34:37 2014 -0400

    piuparts-report.py: Refactor global summary
    
    Factor out the section sorting logic to from generate_global_summary()
    to another function, sections_by_precedence().
---
 debian/changelog   |  1 +
 piuparts-report.py | 28 ++++++++++++----------------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index e5009ad..efda2d7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -41,6 +41,7 @@ piuparts (0.59) UNRELEASED; urgency=low
     accepted and stripped by the parser.
   * piuparts-report.py:
     - Fix indentation of generate_global_summary()
+    - Refactor sections_by_precedence() out of generate_global_summary().
 
  -- Holger Levsen <holger at debian.org>  Thu, 01 May 2014 00:42:23 +0200
 
diff --git a/piuparts-report.py b/piuparts-report.py
index fa92a2e..112832d 100644
--- a/piuparts-report.py
+++ b/piuparts-report.py
@@ -1520,35 +1520,31 @@ class Section:
 
         self.generate_summary(web_host)
 
-def generate_global_summary(dir, sections):
+def sections_by_precedence(sections):
+    precedence = {}
+    count = 0
+    for section in sections:
+        config = Config(section=section, defaults_section="global")
+        config.read(CONFIG_FILE)
+        precedence[section] = (config["precedence"], count)
+        count += 1
 
+    return sorted(sections, key=lambda x: precedence[x])
+
+def generate_global_summary(dir, sections):
     json_name = "summary.json"
 
     logging.debug("Generating global summary")
 
     summary = pkgsummary.new_summary()
 
-    def by_precedence(secname):
-        return(by_precedence.section_precedence[secname])
-
-    by_precedence.section_precedence = {}
-    count = 0
-    for section in sections:
-        config = Config(section=section, defaults_section="global")
-        config.read(CONFIG_FILE)
-        by_precedence.section_precedence[section] = \
-                                        (config["precedence"], count)
-        count += 1
-
-    for section in sorted(sections, key=by_precedence):
+    for section in sections_by_precedence(sections):
        sec_path = os.path.join(dir, section, json_name)
        if os.path.isfile(sec_path):
            sec_summ = pkgsummary.read_summary(sec_path)
            summary = pkgsummary.merge_summary(summary, sec_summ)
 
     summary_path = os.path.join(dir, json_name)
-    if os.path.isfile(summary_path):
-        os.unlink(summary_path)
     pkgsummary.write_summary(summary, summary_path)
 
 # START detect_well_known_errors

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