[Reproducible-commits] [misc] 01/02: clean-notes: use proper logging for output

Mattia Rizzolo mattia at mapreri.org
Wed Jul 8 10:15:13 UTC 2015


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

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

commit aca1e10cfdfe4c63b987d653b200fc6efcde2355
Author: Mattia Rizzolo <mattia at mapreri.org>
Date:   Wed Jul 8 09:59:45 2015 +0000

    clean-notes: use proper logging for output
---
 clean-notes | 64 ++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 31 insertions(+), 33 deletions(-)

diff --git a/clean-notes b/clean-notes
index 2f336b3..8c55711 100755
--- a/clean-notes
+++ b/clean-notes
@@ -14,6 +14,7 @@ import apt
 import sys
 import json
 import yaml
+import logging
 import argparse
 import psycopg2
 import requests
@@ -57,6 +58,7 @@ args = type('DefaultArgs', (object,), {
     'ignore_duplicates': False,
 })
 
+
 if __name__ == '__main__':
     args = parser.parse_args()
 
@@ -73,8 +75,13 @@ if __name__ == '__main__':
         if feature in args.disable:
             args.disable.remove(feature)
 
-    if args.verbose:
-        print(args)
+log = logging.getLogger(__name__)
+log.setLevel(logging.DEBUG if args.verbose else logging.INFO)
+sh = logging.StreamHandler()
+sh.setFormatter(logging.Formatter('{levelname[0]}: {message}', style='{'))
+log.addHandler(sh)
+
+log.debug(args)
 
 # pyyaml does not check for duplicates when reading yaml.
 #
@@ -140,10 +147,6 @@ if __name__ == '__main__':
         yaml.composer.Composer.compose_mapping_node = compose_mapping_node
 
 
-def error(*objs):
-    print("ERROR: ", *objs, file=sys.stderr)
-
-
 def start_udd_connection():
     username = "public-udd-mirror"
     password = "public-udd-mirror"
@@ -151,15 +154,14 @@ def start_udd_connection():
     port = 5432
     db = "udd"
     try:
-        if args.verbose:
-            print("Starting connection to the UDD database")
+        log.debug("Starting connection to the UDD database")
         conn = psycopg2.connect("dbname=" + db +
                                 " user=" + username +
                                 " host=" + host +
                                 " port=" + str(port) +
                                 " password=" + password)
     except:
-        error("Error connecting to the UDD database replica")
+        log.error("Error connecting to the UDD database replica")
         raise
     conn.set_client_encoding('utf8')
     return conn
@@ -217,8 +219,8 @@ def check_notes_validity(notes, testedpkgs):
         if pkg not in testedpkgs:
             badpkgs.append(pkg)
             failed = True
-            print('CRITICAL: the package ' + pkg +
-                  ' was never tested. Maybe it\'s misspelled?')
+            log.critical('the package ' + pkg +
+                         ' was never tested. Maybe it\'s misspelled?')
 
 
 def check_bugs(notes):
@@ -230,8 +232,7 @@ def check_bugs(notes):
         if 'bugs' in notes[pkg]:
             for bug in notes[pkg]['bugs']:
                 bugs.append((str(pkg), int(bug)))
-    if args.verbose:
-        print("looking throught bugs listed in the notes and check whether " +
+    log.debug("looking throught bugs listed in the notes and check whether " +
               "they are usertagged")
     if not bugs:
         return
@@ -248,18 +249,17 @@ def check_bugs(notes):
         # the results from SELECT are a list of one-element tuples, so we have
         # have to look up 1-tuples with the bug number in the list
         if (bug,) not in rows:
-            print("https://bugs.debian.org/" + str(bug) + " in package " +
-                  bugs_package[bug] + " is not usertagged")
+            log.info("https://bugs.debian.org/" + str(bug) + " in package " +
+                     bugs_package[bug] + " is not usertagged")
 
 
 def find_old_notes(testedpkgs, notes):
-    if args.verbose:
-        print("parsing the reproducible.json and the notes to find weirdness")
+    log.debug("parsing the reproducible.json and the notes to find weirdness")
     toremove = []
     for pkg in sorted(notes, key=str):
         if 'version' not in notes[pkg] and \
            'missing-version' not in args.disable:
-            print("There is no version set for the package " + pkg)
+            log.info("There is no version set for the package " + pkg)
             continue
         try:
             item = testedpkgs[pkg]
@@ -268,27 +268,26 @@ def find_old_notes(testedpkgs, notes):
 # https://anonscm.debian.org/cgit/qa/jenkins.debian.net.git/commit/?id=275309
             # and later commits to that file, otherwise this would be
             # quite a issue
-            if args.verbose:
-                print(pkg + ' was not tested. Skipping cruft check.')
+            log.debug(pkg + ' was not tested. Skipping cruft check.')
             continue
         if item['version'] == notes[pkg].get('version') and \
            item['status'] == 'reproducible' and \
            'fixed-magically' not in args.disable:
-            print("The package " + pkg + " has a note for the version " +
-                  item['version'] + " but that version is reproducible")
+            log.info("The package " + pkg + " has a note for the version " +
+                     item['version'] + " but that version is reproducible")
         if item['status'] == 'reproducible' and \
             notes[pkg].get('version') and \
             'now-fixed' not in args.disable and \
             version_compare(str(item['version']),
                             str(notes[pkg]['version'])) > 0:
-            print("The package " + pkg +
-                  " is now reproducible but still listed in the notes")
+            log.info("The package " + pkg +
+                     " is now reproducible but still listed in the notes")
             toremove.append(pkg)
         if notes[pkg].get('version') and \
             version_compare(str(item['version']),
                             str(notes[pkg]['version'])) > 0:
             if 'new-tested-version' not in args.disable:
-                print("The package " + pkg + " has a new tested version")
+                log.info("The package " + pkg + " has a new tested version")
     return toremove
 
 
@@ -325,8 +324,7 @@ def parse_bugs(bugs):
 
     The `bugs` argument is {bug_number: ["usertag1", "usertag2"]}
     """
-    if args.verbose:
-        print("find out if filed bugs are also noted in the notes")
+    log.debug("find out if filed bugs are also noted in the notes")
     packages = {}
     ids = ''
     bugs_list = sorted(bugs.keys())
@@ -367,15 +365,15 @@ def join_notes_bugs(notes, bugs):
             try:
                 if 'bugs' in notes[package]:
                     if bug not in notes[package]['bugs']:
-                        print("https://bugs.debian.org/" + str(bug) +
-                              " in package " + str(package) +
-                              " is not listed in notes.git.")
+                        log.info("https://bugs.debian.org/" + str(bug) +
+                                 " in package " + str(package) +
+                                 " is not listed in notes.git.")
                         notes[package]['bugs'].append(bug)
                 else:
                     notes[package]['bugs'] = [bug]
             except KeyError:
-                print("https://bugs.debian.org/" + str(bug) + " in package " +
-                      str(package) + " is not listed in notes.git.")
+                log.info("https://bugs.debian.org/" + str(bug) + " in " +
+                         str(package) + " is not listed in notes.git.")
                 notes[package] = {}
                 notes[package]['bugs'] = [bug]
                 # just try guessing the version (prefers unstable)
@@ -443,4 +441,4 @@ if __name__ == '__main__':
     if not args.dry_run:
         write_out(notes)
     else:
-        print("Don\'t write out a notes.yml file, as requested (dry-run).")
+        log.info("Don\'t write out a notes.yml file, as requested (dry-run).")

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