[diffoscope] [PATCH] required tools to package name mapping for multiple OS
Levente Polyak
levente at leventepolyak.net
Sun Dec 6 21:32:26 CET 2015
- adding package name mapping for Arch Linux
- optional OS override added to --list-tools
- optional support for OS alias
Patch contributor: Mattia Rizzolo
---
diffoscope/__init__.py | 118 +++++++++++++++++++++++++++++++++----------------
diffoscope/__main__.py | 18 +++++---
2 files changed, 92 insertions(+), 44 deletions(-)
diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 4fb99bb..55461f9 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -36,52 +36,94 @@ ch.setFormatter(formatter)
class RequiredToolNotFound(Exception):
- PROVIDERS = { 'ar': { 'debian': 'binutils-multiarch' }
- , 'bzip2': { 'debian': 'bzip2' }
+ OS_ALIAS = { 'arch': 'Arch Linux'
+ , 'debian': 'Debian'
+ }
+ 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
def get_package(self):
providers = RequiredToolNotFound.PROVIDERS.get(self.command, None)
- if not providers:
+ os = get_current_os()
+ if not providers or not providers[os]:
return None
- # XXX: hardcode Debian for now
- return providers['debian']
+ return providers[os]
+
+
+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..b4c0a0f 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,19 @@ 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, get_current_os
print("External tools required:")
- print(', '.join(tool_required.all))
+ print(', '.join(sorted(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 }))))
+ os = get_current_os() if not os_override else os_override
+ all_os = set(reduce(lambda x, y : x+y, [list(os_entries.keys()) for os_entries in RequiredToolNotFound.PROVIDERS.values()]))
+ if os_override and not os in all_os:
+ print("No package mapping found for: {} (possible values: {})".format(os_override, ", ".join(sorted(all_os))))
+ sys.exit(1)
+ print("Available in {} packages:".format(RequiredToolNotFound.OS_ALIAS[os] if os in RequiredToolNotFound.OS_ALIAS else os))
+ print(', '.join(sorted(filter(None, { RequiredToolNotFound.PROVIDERS[k].get(os, None) for k in tool_required.all }))))
sys.exit(0)
--
2.6.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.reproducible-builds.org/pipermail/diffoscope/attachments/20151206/8a2827d6/attachment.sig>
More information about the diffoscope
mailing list