[Reproducible-commits] [misc] 02/06: move yamlfiles manipulation methods into an importable module

Chris West faux-guest at moszumanska.debian.org
Mon Dec 14 12:06:58 UTC 2015


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

faux-guest pushed a commit to branch master
in repository misc.

commit 7ec984f808de378d47a32f400ca09d2f042837e9
Author: Chris West (Faux) <git at goeswhere.com>
Date:   Mon Dec 14 10:58:35 2015 +0000

    move yamlfiles manipulation methods into an importable module
---
 clean-notes  | 53 +++--------------------------------------------------
 edit-notes   |  6 +++---
 remote.py    |  3 +++
 yamlfiles.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 53 deletions(-)

diff --git a/clean-notes b/clean-notes
index c25cf95..623307a 100755
--- a/clean-notes
+++ b/clean-notes
@@ -9,7 +9,6 @@
 # Depends: python3 python3-apt python3-yaml python3-requests python3-psycopg2
 
 import logging
-import sys
 from apt_pkg import version_compare
 
 import apt
@@ -17,15 +16,13 @@ import argparse
 import psycopg2
 import yaml
 
-
+import yamlfiles
 from remote import load_reproducible_status, RB_SITE
 
 # "apt" is to avoid adding an ugly "apt_pkg.init()" call to fix a "ValueError:
 # _system not initialized" error.
 apt = apt
 
-
-NOTES_YAML = 'packages.yml'
 # {package_name: {version: 0.0.0, comments: "blablabla", bugs: [111, 222],
 #  issues: [issue1, issue2]}, {...}}
 
@@ -204,16 +201,6 @@ def query_udd(query):
     return cursor.fetchall()
 
 
-def load_notes():
-    try:
-        with open(NOTES_YAML, encoding='utf-8') as f:
-            return yaml.safe_load(f)
-    except FileNotFoundError:
-        log.error('%s has not been found in your current directory.  Please '
-                  'cd to the notes directory', NOTES_YAML)
-        sys.exit(1)
-
-
 def check_notes_validity(notes, testedpkgs):
     for pkg in sorted(notes):
         if pkg not in testedpkgs:
@@ -410,46 +397,12 @@ def cleanup_notes(notes, toremove):
     return notes
 
 
-def write_out(notes):
-    out = ''
-    for pkg, values in sorted(notes.items(), key=str):
-        if not any(values.get(key, None)
-                   for key in ['comments', 'issues', 'bugs']):
-            continue
-
-        if pkg[0:2] == '0x':  # otherwise something converts 0xffff to 65535
-            out += "!!str %s:\n" % pkg
-        else:
-            out += "%s:\n" % pkg
-        try:
-            if str(values['version']) == '3.6e-1' or \
-                    pkg == 'cdebconf-entropy':
-                out += "  version: !!str %s\n" % values['version']
-            else:
-                out += "  version: %s\n" % values['version']
-        except KeyError:
-            pass
-        if 'comments' in values:
-            out += "  comments: |\n"
-            for line in values['comments'].strip().split('\n'):
-                out += "    %s\n" % line
-        if 'issues' in values and values['issues']:
-            out += "  issues:\n"
-            for issue in values['issues']:
-                out += "    - %s\n" % issue
-        if 'bugs' in values and values['bugs']:
-            out += "  bugs:\n"
-            for bug in values['bugs']:
-                out += "    - %s\n" % bug
-    with open(NOTES_YAML, 'wb') as f:
-        f.write(out.encode('utf-8'))
-
 if __name__ == '__main__':
     if 'not-usertagged' not in args.disable or \
        'missing-usertagged' not in args.disable or \
        'archived-bugs' not in args.disable:
         conn_udd = start_udd_connection()
-    notes = load_notes()
+    notes = yamlfiles.load_notes()
     if not args.sort_only:
         testedpkgs = load_reproducible_status()
         check_notes_validity(notes, testedpkgs)
@@ -466,7 +419,7 @@ if __name__ == '__main__':
     if 'archived-bugs' not in args.disable:
         detect_archived_bugs(notes)
     if not args.dry_run:
-        write_out(notes)
+        yamlfiles.write_out(notes)
     else:
         log.info("Don't write out the %s file, as requested (dry-run).",
                  NOTES_YAML)
diff --git a/edit-notes b/edit-notes
index d58a537..6188875 100755
--- a/edit-notes
+++ b/edit-notes
@@ -4,7 +4,7 @@ import argparse
 import yaml
 import remote
 
-clean = __import__('clean-notes')
+import yamlfiles
 
 parser = argparse.ArgumentParser()
 parser.add_argument('--verbose', action='store_true')
@@ -28,7 +28,7 @@ if __name__ == '__main__':
     to_remove = set(args.remove_note)
     to_fix.update(to_remove)
 
-    notes = clean.load_notes()
+    notes = yamlfiles.load_notes()
     testedpkgs = remote.load_reproducible_status()
 
     # Validate issues
@@ -84,4 +84,4 @@ if __name__ == '__main__':
             except KeyError:
                 print('%s is not in the notes, skipping removing', pkg)
 
-    clean.write_out(notes)
+    yamlfiles.write_out(notes)
diff --git a/remote.py b/remote.py
index de4d6f5..2d64d5a 100644
--- a/remote.py
+++ b/remote.py
@@ -1,3 +1,6 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
 import json
 
 import requests
diff --git a/yamlfiles.py b/yamlfiles.py
new file mode 100644
index 0000000..042dddb
--- /dev/null
+++ b/yamlfiles.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+import sys
+
+import yaml
+
+NOTES_YAML = 'packages.yml'
+
+
+def load_notes():
+    try:
+        with open(NOTES_YAML, encoding='utf-8') as f:
+            return yaml.safe_load(f)
+    except FileNotFoundError:
+        log.error('%s has not been found in your current directory.  Please '
+                  'cd to the notes directory', NOTES_YAML)
+        sys.exit(1)
+
+
+def write_out(notes):
+    out = ''
+    for pkg, values in sorted(notes.items(), key=str):
+        if not any(values.get(key, None)
+                   for key in ['comments', 'issues', 'bugs']):
+            continue
+
+        if pkg[0:2] == '0x':  # otherwise something converts 0xffff to 65535
+            out += "!!str %s:\n" % pkg
+        else:
+            out += "%s:\n" % pkg
+        try:
+            if str(values['version']) == '3.6e-1' or \
+                    pkg == 'cdebconf-entropy':
+                out += "  version: !!str %s\n" % values['version']
+            else:
+                out += "  version: %s\n" % values['version']
+        except KeyError:
+            pass
+        if 'comments' in values:
+            out += "  comments: |\n"
+            for line in values['comments'].strip().split('\n'):
+                out += "    %s\n" % line
+        if 'issues' in values and values['issues']:
+            out += "  issues:\n"
+            for issue in values['issues']:
+                out += "    - %s\n" % issue
+        if 'bugs' in values and values['bugs']:
+            out += "  bugs:\n"
+            for bug in values['bugs']:
+                out += "    - %s\n" % bug
+    with open(NOTES_YAML, 'wb') as f:
+        f.write(out.encode('utf-8'))

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



More information about the Reproducible-commits mailing list