diff options
| author | Mattia Rizzolo <mattia@debian.org> | 2017-07-14 09:45:04 (GMT) |
|---|---|---|
| committer | Mattia Rizzolo <mattia@debian.org> | 2017-07-14 09:47:35 (GMT) |
| commit | e62306e17e8a9b981d3b7f427bc99f8582a0301a (patch) | |
| tree | 689cd36fff0d1c2df8e458e871eb26816a698520 | |
| parent | c8927db98131a129c5d7354bfe8a6b0886ca66f8 (diff) | |
tools: add a get_package_provider() function, returning the package name that best matches the system
This function uses distro.like() to obtain a list of distributions
similar to the one we are running on.
It means that we will, for example, be able to suggest Debian packages
when running under Ubuntu.
Gbp-Dch: Short
Signed-off-by: Mattia Rizzolo <mattia@debian.org>
| -rw-r--r-- | diffoscope/tools.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/diffoscope/tools.py b/diffoscope/tools.py index 148758b..fd483b4 100644 --- a/diffoscope/tools.py +++ b/diffoscope/tools.py @@ -29,6 +29,7 @@ except ImportError: from distutils.spawn import find_executable from .profiling import profile +from .external_tools import EXTERNAL_TOOLS # Memoize calls to ``distutils.spawn.find_executable`` to avoid excessive stat # calls @@ -81,3 +82,27 @@ def get_current_os(): if distro: return distro.id() return system # noqa + +def get_current_distro_like(): + if distro: + return distro.like().split() + else: + return [] + +def get_package_provider(tool, os=None): + try: + providers = EXTERNAL_TOOLS[tool] + except KeyError: # noqa + return None + + try: + return providers[get_current_os()] + except KeyError: + # lookup failed, try to look for a package for a similar distro + for d in get_current_distro_like(): + try: + return providers[d] + except KeyError: + pass + + return None |
