[Reproducible-commits] [misc] 01/01: unreproducible-installed: use python-apt (instead of dpkg subprocess) if available.

Valentin Lorentz progval-guest at moszumanska.debian.org
Tue Aug 18 15:28:59 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 670d3da945da03a5a3142312a640924e20f60702
Author: Valentin Lorentz <progval at progval.net>
Date:   Tue Aug 18 17:30:14 2015 +0200

    unreproducible-installed: use python-apt (instead of dpkg subprocess) if available.
---
 unreproducible-installed | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/unreproducible-installed b/unreproducible-installed
index 455391a..294192e 100755
--- a/unreproducible-installed
+++ b/unreproducible-installed
@@ -16,6 +16,11 @@ import os.path
 import argparse
 import subprocess
 
+try:
+    import apt
+except ImportError:
+    apt = None
+
 if sys.version_info[0] >= 3: # Python 3
     from urllib.request import urlopen
 else: # Python 2
@@ -109,13 +114,21 @@ def filter_packages(args):
                       if all(f(x) for f in filters)}
     return unreproducible
 
-def get_installed_packages(args):
-    dpkg_output = subprocess.check_output(['dpkg', '-l'], universal_newlines=True)
-    dpkg_list = dpkg_output.split('\n')
-    installed = {x.split('  ')[1].split(':')[0] # keep the second field, strip arch
-                 for x in dpkg_list
-                 if x.startswith('i')} # ignore headers
-    return installed
+if apt:
+    def get_installed_packages(args):
+        installed = {x.name
+                     for x in apt.cache.Cache()
+                     if x.installed}
+        return installed
+else:
+    # Fallback in case python-apt is not installed.
+    def get_installed_packages(args):
+        dpkg_output = subprocess.check_output(['dpkg', '-l'], universal_newlines=True)
+        dpkg_list = dpkg_output.split('\n')
+        installed = {x.split('  ')[1].split(':')[0] # keep the second field, strip arch
+                     for x in dpkg_list
+                     if x.startswith('i')} # ignore headers
+        return installed
 
 def main(args):
     unreproducible = filter_packages(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