[diffoscope] 02/03: Add support for package names for OS other than Debian

Jérémy Bobbio lunar at moszumanska.debian.org
Sat Dec 12 19:25:18 CET 2015


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

lunar pushed a commit to branch master
in repository diffoscope.

commit 98aa0a142995521fa2736b968fe74e9ef8516ce3
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sat Dec 12 18:05:15 2015 +0000

    Add support for package names for OS other than Debian
    
    Previously, we always assumed we were running on Debian.
    RequiredToolNotFound.get_package() will now try to determine the current
    operating system and display the matching package name.
    
    The --list-tools command-line option now supports an optional argument
    to display a given operating system. When --list-tools is called without
    an optional argument, the list of packages for the current operating
    system will be displayed. If the current operating system is unknown, we
    will display the list of packages for all known operating systems to
    give some cues.
    
    Initial implementation by Mattia Rizzolo, then greatly enhanced by
    anthraxx.
---
 debian/rules           |   2 +-
 diffoscope/__init__.py | 115 +++++++++++++++++++++++++++++++++----------------
 diffoscope/__main__.py |  29 ++++++++++---
 3 files changed, 101 insertions(+), 45 deletions(-)

diff --git a/debian/rules b/debian/rules
index 9f507c3..516ab56 100755
--- a/debian/rules
+++ b/debian/rules
@@ -16,7 +16,7 @@ override_dh_python3:
 	dh_python3 --recommends=python-debian --recommends=rpm-python --recommends=tlsh
 
 override_dh_gencontrol:
-	TOOLS="$$(bin/diffoscope --list-tools | tail -n 1 | \
+	TOOLS="$$(bin/diffoscope --list-tools=debian | tail -n 1 | \
 		sed -e 's/\(^\| \)\(coreutils\|diffutils\|e2fsprogs\|findutils\|gzip\|tar\)\(,\|$$\)//g')"; \
 		[ -n "$$TOOLS" ] || { echo '--list-tools failed' >&2; exit 1; }; \
 		echo "diffoscope:Recommends=$$TOOLS" >> debian/diffoscope.substvars
diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 4fb99bb..4a003ff 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -34,44 +34,78 @@ logger.addHandler(ch)
 formatter = logging.Formatter('%(levelname)8s %(message)s')
 ch.setFormatter(formatter)
 
+OS_NAMES = { 'arch': 'Arch Linux'
+           , 'debian': 'Debian'
+           }
 
 class RequiredToolNotFound(Exception):
-    PROVIDERS = { 'ar':         { 'debian': 'binutils-multiarch' }
-                , 'bzip2':      { 'debian': 'bzip2' }
+    PROVIDERS = { 'ar':         { 'debian': 'binutils-multiarch',
+                                  'arch': 'binutils'}
+                , 'bzip2':      { 'debian': 'bzip2',
+                                  'arch': 'bzip2'}
                 , 'cbfstool':   {}
-                , 'cmp':        { 'debian': 'diffutils' }
-                , 'cpio':       { 'debian': 'cpio' }
-                , 'diff':       { 'debian': 'diffutils' }
-                , 'enjarify':   { 'debian': 'enjarify' }
-                , 'file':       { 'debian': 'file' }
-                , 'find':       { 'debian': 'findutils' }
-                , 'getfacl':    { 'debian': 'acl' }
-                , 'ghc':        { 'debian': 'ghc' }
-                , 'gpg':        { 'debian': 'gnupg' }
-                , 'gzip':       { 'debian': 'gzip' }
-                , 'img2txt':    { 'debian': 'caca-utils' }
-                , 'isoinfo':    { 'debian': 'genisoimage' }
-                , 'javap':      { 'debian': 'default-jdk | java-sdk' }
-                , 'ls':         { 'debian': 'coreutils' }
-                , 'lsattr':     { 'debian': 'e2fsprogs' }
-                , 'msgunfmt':   { 'debian': 'gettext' }
-                , 'objdump':    { 'debian': 'binutils-multiarch' }
-                , 'pdftk':      { 'debian': 'pdftk' }
-                , 'pdftotext':  { 'debian': 'poppler-utils' }
-                , 'pedump':     { 'debian': 'mono-utils' }
-                , 'ppudump':    { 'debian': 'fp-utils' }
-                , 'readelf':    { 'debian': 'binutils-multiarch' }
-                , 'rpm2cpio':   { 'debian': 'rpm2cpio' }
-                , 'showttf':    { 'debian': 'fontforge-extras' }
-                , 'sng':        { 'debian': 'sng' }
-                , 'stat':       { 'debian': 'coreutils' }
-                , 'sqlite3':    { 'debian': 'sqlite3'}
-                , 'tar':        { 'debian': 'tar'}
-                , 'unsquashfs': { 'debian': 'squashfs-tools' }
-                , 'xxd':        { 'debian': 'vim-common' }
-                , 'xz':         { 'debian': 'xz-utils' }
-                , 'zipinfo':    { 'debian': 'unzip' }
-              }
+                , 'cmp':        { 'debian': 'diffutils',
+                                  'arch': 'diffutils'}
+                , 'cpio':       { 'debian': 'cpio',
+                                  'arch': 'cpio'}
+                , 'diff':       { 'debian': 'diffutils',
+                                  'arch': 'diffutils'}
+                , 'enjarify':   { 'debian': 'enjarify',
+                                  'arch': 'enjarify'}
+                , 'file':       { 'debian': 'file',
+                                  'arch': 'file'}
+                , 'find':       { 'debian': 'findutils',
+                                  'arch': 'findutils'}
+                , 'getfacl':    { 'debian': 'acl',
+                                  'arch': 'acl'}
+                , 'ghc':        { 'debian': 'ghc',
+                                  'arch': 'ghc'}
+                , 'gpg':        { 'debian': 'gnupg',
+                                  'arch': 'gnupg'}
+                , 'gzip':       { 'debian': 'gzip',
+                                  'arch': 'gzip'}
+                , 'img2txt':    { 'debian': 'caca-utils',
+                                  'arch': 'libcaca'}
+                , 'isoinfo':    { 'debian': 'genisoimage',
+                                  'arch': 'cdrkit'}
+                , 'javap':      { 'debian': 'default-jdk | java-sdk',
+                                  'arch': 'java-environment'}
+                , 'ls':         { 'debian': 'coreutils',
+                                  'arch': 'coreutils'}
+                , 'lsattr':     { 'debian': 'e2fsprogs',
+                                  'arch': 'e2fsprogs'}
+                , 'msgunfmt':   { 'debian': 'gettext',
+                                  'arch': 'gettext'}
+                , 'objdump':    { 'debian': 'binutils-multiarch',
+                                  'arch': 'binutils'}
+                , 'pdftk':      { 'debian': 'pdftk'}
+                , 'pdftotext':  { 'debian': 'poppler-utils',
+                                  'arch': 'poppler'}
+                , 'pedump':     { 'debian': 'mono-utils',
+                                  'arch': 'mono-tools'}
+                , 'ppudump':    { 'debian': 'fp-utils',
+                                  'arch': 'fpc'}
+                , 'readelf':    { 'debian': 'binutils-multiarch',
+                                  'arch': 'binutils'}
+                , 'rpm2cpio':   { 'debian': 'rpm2cpio',
+                                  'arch': 'rpmextract'}
+                , 'showttf':    { 'debian': 'fontforge-extras'}
+                , 'sng':        { 'debian': 'sng'}
+                , 'stat':       { 'debian': 'coreutils',
+                                  'arch': 'coreutils'}
+                , 'sqlite3':    { 'debian': 'sqlite3',
+                                  'arch': 'sqlite'}
+                , 'tar':        { 'debian': 'tar',
+                                  'arch': 'tar'}
+                , 'unsquashfs': { 'debian': 'squashfs-tools',
+                                  'arch': 'squashfs-tools'}
+                , 'xxd':        { 'debian': 'vim-common',
+                                  'arch': 'vim'}
+                , 'xz':         { 'debian': 'xz-utils',
+                                  'arch': 'xz' }
+                , 'zipinfo':    { 'debian': 'unzip',
+                                  'arch': 'unzip'}
+                }
 
     def __init__(self, command):
         self.command = command
@@ -80,8 +114,15 @@ class RequiredToolNotFound(Exception):
         providers = RequiredToolNotFound.PROVIDERS.get(self.command, None)
         if not providers:
             return None
-        # XXX: hardcode Debian for now
-        return providers['debian']
+        return providers.get(get_current_os(), None)
+
+
+def get_current_os():
+    import platform
+    system = platform.system()
+    if system == "Linux":
+        return platform.linux_distribution()[0]
+    return system
 
 
 # decorator that checks if the specified tool is installed
diff --git a/diffoscope/__main__.py b/diffoscope/__main__.py
index c027b54..3363186 100644
--- a/diffoscope/__main__.py
+++ b/diffoscope/__main__.py
@@ -43,7 +43,7 @@ def create_parser():
                     'of Debian packages')
     parser.add_argument('--version', action='version',
                         version='diffoscope %s' % VERSION)
-    parser.add_argument('--list-tools', nargs=0, action=ListToolsAction,
+    parser.add_argument('--list-tools', nargs='?', type=str, action=ListToolsAction,
                         help='show external tools required and exit')
     parser.add_argument('--debug', dest='debug', action='store_true',
                         default=False, help='display debug messages')
@@ -97,13 +97,28 @@ def make_printer(path):
 
 
 class ListToolsAction(argparse.Action):
-    def __call__(self, parser, namespace, values, option_string=None):
-        from diffoscope import tool_required, RequiredToolNotFound
+    def __call__(self, parser, namespace, os_override, option_string=None):
+        from functools import reduce
+        from diffoscope import tool_required, RequiredToolNotFound, OS_NAMES, get_current_os
         print("External tools required:")
-        print(', '.join(tool_required.all))
-        print()
-        print("Available in packages:")
-        print(', '.join(sorted(filter(None, { RequiredToolNotFound.PROVIDERS[k].get('debian', None) for k in tool_required.all }))))
+        print(', '.join(sorted(tool_required.all)))
+        if os_override:
+            if os_override in OS_NAMES.keys():
+                os_list = [os_override]
+            else:
+                print()
+                print("No package mapping found for: {} (possible values: {})".format(os_override, ", ".join(sorted(OS_NAMES.keys()))))
+                sys.exit(1)
+        else:
+            current_os = get_current_os()
+            if current_os in OS_NAMES.keys():
+                os_list = [current_os]
+            else:
+                os_list = OS_NAMES.keys()
+        for os in os_list:
+            print()
+            print("Available in {} packages:".format(OS_NAMES[os] if os in OS_NAMES else os))
+            print(', '.join(sorted(filter(None, { RequiredToolNotFound.PROVIDERS.get(k, {}).get(os, None) for k in tool_required.all }))))
         sys.exit(0)
 
 

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


More information about the diffoscope mailing list