From e9c9865b6d12adb3e70d76f9130ac2bd790655dc Mon Sep 17 00:00:00 2001 From: Yuguang Wang Date: Wed, 20 Sep 2023 16:27:43 +0800 Subject: [PATCH] csmock: add shortcut to retrieve coverity version --- py/common/util.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/py/common/util.py b/py/common/util.py index cfab8979..8e7f4cfa 100644 --- a/py/common/util.py +++ b/py/common/util.py @@ -16,6 +16,7 @@ # along with csmock. If not, see . import re +import subprocess def shell_quote(str_in): @@ -121,3 +122,19 @@ def dirs_to_scan_by_args(parser, args, props, tool): props.need_rpm_bi = True return dirs_to_scan + + +def get_coverity_version(install_dir="/opt/coverity/"): + """ + Retrieve the version information from the coverity executable. + + Returns: + string of the version information or None otherwise. + """ + executable_path = f"{install_dir}bin/coverity" + try: + version_info = subprocess.check_output([executable_path, "--version"]) + version_text = version_info.decode("utf-8") + return version_text.strip().split()[0] + except (subprocess.CalledProcessError, FileNotFoundError): + return None