[Reproducible-commits] [misc] 03/03: clean-notes: do some pep8 cleanups
Mattia Rizzolo
mapreri-guest at moszumanska.debian.org
Thu Feb 12 01:49:04 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 4da035c4b6d1c7983525f849d97ed8b706806a95
Author: Mattia Rizzolo <mattia at mapreri.org>
Date: Thu Feb 12 02:48:07 2015 +0100
clean-notes: do some pep8 cleanups
---
clean-notes | 64 +++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 23 deletions(-)
diff --git a/clean-notes b/clean-notes
index ea38ffb..b55fb43 100755
--- a/clean-notes
+++ b/clean-notes
@@ -6,10 +6,12 @@
# 2015 Mattia Rizzolo <mattia at mapreri.org>
# Licensed under WTFPL — http://www.wtfpl.net/txt/copying/
#
-# Depends: python3 python3-apt python3-json python3-yaml python3-requests python3-psycopg2
+# Depends: python3 python3-apt python3-json python3-yaml python3-requests
+# python3-psycopg2
-import apt # this is to avoid adding an ugly "apt_pkg.init()" call to
- # fix a "ValueError: _system not initialized" error.
+# "apt" is to avoid adding an ugly "apt_pkg.init()" call to
+# fix a "ValueError: _system not initialized" error.
+import apt
import sys
import json
import yaml
@@ -29,7 +31,7 @@ description = """Housekeep the packages.yml file from the notes.git repository.
This script is also able to show you other information:
* missing-version: list notes without version
-* fixed-magically: list notes which version is marked as reproducible by jenkins
+* fixed-magically: list notes which version is marked as reproducible
* new-tested-version: there is a new version tested in jenkins, but the package
is not reproducible anyway...
* missing-usertagged: list usertagged bugs but not listed in the notes
@@ -40,18 +42,18 @@ parser = argparse.ArgumentParser(description=description,
parser.add_argument('-e', '--enable', action='append', default=[],
help="enable a particular view (choose from above)")
parser.add_argument('-d', '--disable', action='append', default=[],
- help="enable a particular view (choose from above)")
+ help="disable a particular view (choose from above)")
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-n", "--dry-run", action="store_true")
args = parser.parse_args()
disabled_features = [
'fixed-magically',
+ 'new-tested-version',
+ ]
# 'missing-version',
# 'missing-usertagged',
- 'new-tested-version',
# 'not-usertagged',
- ]
args.disable.extend(disabled_features)
for feature in args.enable:
if feature in args.disable:
@@ -60,9 +62,11 @@ for feature in args.enable:
if args.verbose:
print(args)
+
def error(*objs):
print("ERROR: ", *objs, file=sys.stderr)
+
def start_udd_connection():
username = "public-udd-mirror"
password = "public-udd-mirror"
@@ -73,21 +77,23 @@ def start_udd_connection():
if args.verbose:
print("Starting connection to the UDD database")
conn = psycopg2.connect("dbname=" + db +
- " user=" + username +
- " host=" + host +
- " port=" + str(port) +
- " password=" + password)
+ " user=" + username +
+ " host=" + host +
+ " port=" + str(port) +
+ " password=" + password)
except:
error("Error connecting to the UDD database replica")
raise
conn.set_client_encoding('utf8')
return conn
+
def query_udd(query):
cursor = conn.cursor()
cursor.execute(query)
return cursor.fetchall()
+
def load_reproducible_status():
try:
with open('reproducible.json') as fd:
@@ -97,11 +103,13 @@ def load_reproducible_status():
r = r.json()
return r
+
def load_notes():
with open(notes_yaml, encoding='utf-8') as fd:
notes = yaml.load(fd)
return notes
+
def check_notes_validity(notes, testedpkgs):
failed = False
badpkgs = []
@@ -110,12 +118,13 @@ def check_notes_validity(notes, testedpkgs):
if pkg not in allpkgs:
badpkgs.append(pkg)
failed = True
- print('CRITICAL: the package ' + pkg + \
+ print('CRITICAL: the package ' + pkg +
' was never tested. Maybe it\'s misspelled?')
if failed:
print('Aborting, please fix the notes file')
sys.exit(1)
+
def check_bugs(notes):
"""
This function check whether all the bugs listed in notes.git are usertagged
@@ -140,7 +149,8 @@ def check_bugs(notes):
for bug in bugs_list:
if bug not in rows:
print("bug #" + str(bug) + " in package " + bugs_package[bug] +
- " is not usertagged")
+ " is not usertagged")
+
def find_old_notes(testedpkgs, notes):
if args.verbose:
@@ -157,12 +167,13 @@ def find_old_notes(testedpkgs, notes):
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")
+ + item['version'] + " but that version is reproducible")
if item['package'] == pkg and \
item['status'] == 'reproducible' and \
apt_pkg.version_compare(str(item['version']),
str(notes[pkg]['version'])) > 0:
- print("The package " + pkg + " it's now reproducible but still listed in the notes")
+ print("The package " + pkg +
+ " is now reproducible but still listed in the notes")
toremove.append(pkg)
if item['package'] == pkg and \
apt_pkg.version_compare(str(item['version']),
@@ -171,12 +182,15 @@ def find_old_notes(testedpkgs, notes):
print("The package " + pkg + " has a new tested version")
return toremove
+
def is_virtual_package(package):
- rows = query_udd("""SELECT source FROM sources WHERE source='%s'""" % package)
+ query = "SELECT source FROM sources WHERE source='%s'" % package
+ rows = query_udd(query)
if len(rows) > 0:
return False
return True
+
def get_bugs():
rows = query_udd("""SELECT * FROM bugs_usertags WHERE
email='reproducible-builds at lists.alioth.debian.org'""")
@@ -189,6 +203,7 @@ def get_bugs():
bugs[tag[2]] = [tag[1]]
return bugs
+
def parse_bugs(bugs):
"""
This function return a dict:
@@ -205,7 +220,7 @@ def parse_bugs(bugs):
packages = {}
ids = ''
bugs_list = sorted(bugs.keys())
- ignored_tags=['toolchain', 'infrastructure']
+ ignored_tags = ['toolchain', 'infrastructure']
OR = ''
for bug in bugs_list[:-1]:
if not [i for i in bugs[bug] if i in ignored_tags]:
@@ -216,7 +231,7 @@ def parse_bugs(bugs):
query = """SELECT id, source, done FROM bugs WHERE %s""" % ids
rows = query_udd(query)
for item in rows:
- if item[2]: # do not consider closed bugs
+ if item[2]: # do not consider closed bugs
continue
if is_virtual_package(item[1]):
continue
@@ -235,6 +250,7 @@ def parse_bugs(bugs):
packages[item[1]]['usertags'] = [tag]
return packages
+
def join_notes_bugs(notes, bugs):
for package in bugs:
for bug in bugs[package]['bugs']:
@@ -242,29 +258,32 @@ def join_notes_bugs(notes, bugs):
if 'bugs' in notes[package]:
if bug not in notes[package]['bugs']:
print("bug #" + str(bug) + " in package " +
- str(package) + " is not listed in notes.git.")
+ str(package) + " is not listed in notes.git.")
notes[package]['bugs'].append(bug)
else:
notes[package]['bugs'] = [bug]
except KeyError:
print("bug #" + str(bug) + " in package " + str(package) +
- " is not listed in notes.git.")
+ " is not listed in notes.git.")
notes[package] = {}
notes[package]['bugs'] = [bug]
return notes
+
def cleanup_notes(notes, toremove):
for pkg in toremove:
del notes[pkg]
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'])):
+ if not any(values.get(key, None)
+ for key in ['comments', 'issues', 'bugs']):
continue
- if pkg[0:2] == '0x': # otherwise something will convert 0xffff to 65535
+ if pkg[0:2] == '0x': # otherwise something converts 0xffff to 65535
out += ("!!str " + str(pkg) + ":\n")
else:
out += (str(pkg) + ":\n")
@@ -307,4 +326,3 @@ if __name__ == '__main__':
write_out(notes)
else:
print("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