MCPcopy
hub / github.com/freedomofpress/dangerzone / get_runtime_version

Function get_runtime_version

dangerzone/container_utils.py:36–66  ·  view source on GitHub ↗

Get the major/minor parts of the Docker/Podman version. Some of the operations we perform in this module rely on some Podman features that are not available across all of our platforms. In order to have a proper fallback, we need to know the Podman version. More specifically, we're fine

()

Source from the content-addressed store, hash-verified

34
35
36def get_runtime_version() -> tuple[int, int]:
37 """Get the major/minor parts of the Docker/Podman version.
38
39 Some of the operations we perform in this module rely on some Podman features
40 that are not available across all of our platforms. In order to have a proper
41 fallback, we need to know the Podman version. More specifically, we're fine with
42 just knowing the major and minor version, since writing/installing a full-blown
43 semver parser is an overkill.
44 """
45 # Get the Docker/Podman version, using a Go template.
46 podman = init_podman_command()
47 query = "{{.Client.Version}}"
48
49 try:
50 version = podman.run(["version", "-f", query])
51 assert isinstance(version, str)
52 except Exception as e:
53 msg = f"Could not get the version of Podman: {e}"
54 raise RuntimeError(msg) from e
55
56 # Parse this version and return the major/minor parts, since we don't need the
57 # rest.
58 try:
59 major, minor, _ = version.split(".", 3)
60 return (int(major), int(minor))
61 except ValueError as e:
62 msg = (
63 f"Could not parse the version of Podman (found: '{version}') due to the"
64 f" following error: {e}"
65 )
66 raise RuntimeError(msg)
67
68
69def get_podman_path() -> Path | None:

Callers 1

Calls 2

init_podman_commandFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected