[Reproducible-commits] [misc] 01/01: unreproducible-installed: Add filter --with-issue.

Valentin Lorentz progval-guest at moszumanska.debian.org
Tue Aug 18 15:47:40 UTC 2015


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

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

commit 4345c948bb8363284401afdf284a5b9667a34550
Author: Valentin Lorentz <progval at progval.net>
Date:   Tue Aug 18 17:48:55 2015 +0200

    unreproducible-installed: Add filter --with-issue.
---
 unreproducible-installed | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/unreproducible-installed b/unreproducible-installed
index 294192e..b2ac14c 100755
--- a/unreproducible-installed
+++ b/unreproducible-installed
@@ -20,6 +20,10 @@ try:
     import apt
 except ImportError:
     apt = None
+try:
+    import yaml
+except ImportError:
+    yaml = None
 
 if sys.version_info[0] >= 3: # Python 3
     from urllib.request import urlopen
@@ -62,6 +66,9 @@ filter_group.add_argument('--exclude-status', type=str, action='append',
     help='The package status to remove. Use this option multiple times to '
          'exclude many. Defaults to "%s".' %
          ', '.join(DEFAULT_EXCLUDED_STATUSES))
+filter_group.add_argument('--with-issue', type=str, action='append',
+    help='Keep only packages with the given issue. Use this option multiple '
+         'times to make it an OR clause.')
 
 def find_data(args):
     """Search for the reproducible.json file and load it."""
@@ -94,7 +101,7 @@ def download_data(args):
         fd.write(response)
     return json.loads(response)
 
-def filter_packages(args):
+def filter_packages(args, notes):
     data = find_data(args)
     if not data:
         data = download_data(args)
@@ -109,6 +116,13 @@ def filter_packages(args):
                                  DEFAULT_EXCLUDED_STATUSES)
     filters.append(lambda x:x['status'] not in exclude_statuses)
 
+    if args.with_issue:
+        with_issues = frozenset(args.with_issue)
+        def predicate(x):
+            issues = set(notes.get(x['package'], {}).get('issues', [])) & with_issues
+            return bool(issues)
+        filters.append(predicate)
+
     unreproducible = {x['package']
                       for x in data
                       if all(f(x) for f in filters)}
@@ -131,13 +145,14 @@ else:
         return installed
 
 def main(args):
-    unreproducible = filter_packages(args)
-
-    if args.ignore_with_bugs:
-        import yaml
+    if yaml:
         with open(args.package_notes_file) as fd:
             notes = yaml.load(fd)
+    else:
+        notes = None
+    unreproducible = filter_packages(args, notes=notes)
 
+    if args.ignore_with_bugs:
         unreproducible = {x for x in unreproducible if 'bugs' not in notes.get(x, {})}
 
     installed = get_installed_packages(args)
@@ -147,10 +162,14 @@ def main(args):
 
 if __name__ == '__main__':
     args = parser.parse_args()
-    if args.ignore_with_bugs:
-        try:
-            import yaml
-        except ImportError:
-            print('--ignore-with-bugs requires PyYaml to be installed.')
+    if not yaml:
+        require_yaml = ['ignore-with-bugs', 'with-issue']
+        errors = []
+        for option in require_yaml:
+            if not getattr(args, option.replace('-', '_')):
+                errors.append(option)
+        if errors:
+            print('Requires PyYaml to be installed: --%s' %
+                  ', --'.join(errors))
             exit(1)
     main(args)

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