Skip to content
Snippets Groups Projects
Commit 248b06aa authored by Hans-Christoph Steiner's avatar Hans-Christoph Steiner
Browse files

diffoscope.tools.get_tools() to programmatically fetch config

In F-Droid, we use diffoscope in automated verification of APKs.  We need to
include the diffoscope config and version in a JSON report so that the
scheduler can know whether it needs to rerun diffoscope on a file. If the
diffoscope configuration or version has changed, then it should be run again.
parent fda75c73
No related branches found
No related tags found
1 merge request!76diffoscope.tools.get_tools() to programmatically fetch config
Pipeline #239068 passed
......@@ -31,6 +31,7 @@ import traceback
from . import VERSION
from .path import set_path
from .tools import (
get_tools,
tool_check_installed,
tool_prepend_prefix,
python_module_missing,
......@@ -535,34 +536,8 @@ class ListToolsAction(argparse.Action):
# populated.
ComparatorManager().reload()
external_tools = sorted(tool_required.all)
if self.only_missing:
external_tools = [
tool
for tool in external_tools
if not tool_check_installed(tool)
]
print("External-Tools-Required: ", end="")
print(", ".join(external_tools))
current_os = get_current_os()
os_list = [current_os] if (current_os in OS_NAMES) else iter(OS_NAMES)
if os_override:
os_list = [os_override]
for os_ in os_list:
tools = set()
print("Available-in-{}-packages: ".format(OS_NAMES[os_]), end="")
for x in external_tools:
try:
tools.add(EXTERNAL_TOOLS[x][os_])
except KeyError:
pass
print(", ".join(sorted(tools)))
print("Missing-Python-Modules: ", end="")
print(", ".join(sorted(python_module_missing.modules)))
for k, v in sorted(get_tools(self.only_missing).items()):
print("%s: %s" % (k, ", ".join(v)))
sys.exit(0)
......
......@@ -46,6 +46,36 @@ OS_NAMES = collections.OrderedDict(
)
def get_tools(only_missing=False):
"""Return the tool configuration in a dict"""
d = {}
external_tools = sorted(tool_required.all)
if only_missing:
external_tools = [
tool for tool in external_tools if not tool_check_installed(tool)
]
d["External-Tools-Required"] = tuple(external_tools)
current_os = get_current_os()
os_list = [current_os] if (current_os in OS_NAMES) else iter(OS_NAMES)
for os_ in os_list:
tools = set()
for x in external_tools:
try:
tools.add(EXTERNAL_TOOLS[x][os_])
except KeyError:
pass
d["Available-in-{}-packages".format(OS_NAMES[os_])] = tuple(
sorted(tools)
)
d["Missing-Python-Modules"] = tuple(sorted(python_module_missing.modules))
return d
def get_tool_name(tool):
return REMAPPED_TOOL_NAMES.get(tool, tool)
......
......@@ -35,6 +35,23 @@ def test_all_tools_are_listed():
pytest.fail(f"{x} is not present in EXTERNAL_TOOLS")
def test_get_tools():
# Note the ordering of this test (see: f1d744da16)
from diffoscope.comparators import ComparatorManager
from diffoscope.tools import get_tools
ComparatorManager().reload()
tools = get_tools()
missing_tools = get_tools(only_missing=True)
k = "External-Tools-Required"
for x in missing_tools[k]:
if x not in tools[k]:
pytest.fail(
f"{x} must be present for {k} in tools and only_missing"
)
def test_sbin_added_to_path():
from diffoscope.tools import tool_required
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment