File: print_tool_versions.py

package info (click to toggle)
aws-crt-python 0.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 75,932 kB
  • sloc: ansic: 418,984; python: 23,626; makefile: 6,035; sh: 4,075; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (74 lines) | stat: -rwxr-xr-x 1,898 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0


import logging
import pathlib
import shutil
import subprocess


_TOOLS = [
    "cadical",
    "cbmc",
    "cbmc-viewer",
    "cbmc-starter-kit-update",
    "kissat",
    "litani",
]


def _format_versions(table):
    lines = [
        "<table>",
        '<tr><td colspan="2" style="font-weight: bold">Tool Versions</td></tr>',
    ]
    for tool, version in table.items():
        if version:
            v_str = f'<code><pre style="margin: 0">{version}</pre></code>'
        else:
            v_str = '<em>not found</em>'
        lines.append(
            f'<tr><td style="font-weight: bold; padding-right: 1em; '
            f'text-align: right;">{tool}:</td>'
            f'<td>{v_str}</td></tr>')
    lines.append("</table>")
    return "\n".join(lines)


def _get_tool_versions():
    ret = {}
    for tool in _TOOLS:
        err = f"Could not determine version of {tool}: "
        ret[tool] = None
        if not shutil.which(tool):
            logging.error("%s'%s' not found on $PATH", err, tool)
            continue
        cmd = [tool, "--version"]
        proc = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE)
        try:
            out, _ = proc.communicate(timeout=10)
        except subprocess.TimeoutExpired:
            logging.error("%s'%s --version' timed out", err, tool)
            continue
        if proc.returncode:
            logging.error(
                "%s'%s --version' returned %s", err, tool, str(proc.returncode))
            continue
        ret[tool] = out.strip()
    return ret


def main():
    exe_name = pathlib.Path(__file__).name
    logging.basicConfig(format=f"{exe_name}: %(message)s")

    table = _get_tool_versions()
    out = _format_versions(table)
    print(out)


if __name__ == "__main__":
    main()