[diffoscope] 02/03: tools: add a get_package_provider() function, returning the package name that best matches the system
Mattia Rizzolo
mattia at debian.org
Fri Jul 14 12:01:50 CEST 2017
This is an automated email from the git hooks/post-receive script.
mattia pushed a commit to branch master
in repository diffoscope.
commit e62306e17e8a9b981d3b7f427bc99f8582a0301a
Author: Mattia Rizzolo <mattia at debian.org>
Date: Fri Jul 14 11:45:04 2017 +0200
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 at debian.org>
---
diffoscope/tools.py | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list