From: Aymeric Sonolet Date: Wed, 31 Jan 2024 11:57:38 +0000 (+0100) Subject: spns #40790: on Debian distributions, use dpkg-query instead of apt to check system... X-Git-Tag: V9_13_0~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f84f9155fd7f02e80ed7826061f9c20cfeb1d8ea;p=tools%2Fsat.git spns #40790: on Debian distributions, use dpkg-query instead of apt to check system dependancies. x5 in improvement --- diff --git a/src/product.py b/src/product.py index 28948da..a679e44 100644 --- a/src/product.py +++ b/src/product.py @@ -1312,7 +1312,7 @@ def check_system_dep(distrib, check_cmd, product_info): if "rpm_dev" in additional_sysinfo: for pkg in additional_sysinfo.rpm_dev: build_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg) - if check_cmd[0]=="apt": + if check_cmd[0]=="apt" or check_cmd[0]=="dpkg-query": if "apt" in sysinfo: for pkg in sysinfo.apt: runtime_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg) diff --git a/src/system.py b/src/system.py index 17a7c06..b007608 100644 --- a/src/system.py +++ b/src/system.py @@ -394,22 +394,28 @@ def get_pkg_check_cmd(dist_name): linux="DB" manager_msg_err="Error : command failed because sat was not able to find rpm command" - # 1- search for an installed package manager (rpm on rh, apt on db) - cmd_which_rpm=["which", "rpm"] - cmd_which_apt=["which", "apt"] + # 1- search for an installed package manager (rpm on rh, apt or dpkg-query on db) + cmd_which_rpm = ["which", "rpm"] + cmd_which_apt = ["which", "apt"] + cmd_which_dpkg = ["which", "dpkg-query"] with open(os.devnull, 'w') as devnull: # 1) we search for apt (debian based systems) - completed=SP.call(cmd_which_apt,stdout=devnull, stderr=SP.STDOUT) + completed=SP.call(cmd_which_dpkg,stdout=devnull, stderr=SP.STDOUT) if completed==0 and linux=="DB": - cmd_is_package_installed=["apt", "list", "--installed"] + cmd_is_package_installed = ["dpkg-query", "--no-pager", "-l"] else: - # 2) if apt not found search for rpm (redhat) - completed=SP.call(cmd_which_rpm,stdout=devnull, stderr=SP.STDOUT) # only 3.8! ,capture_output=True) - if completed==0 and linux=="RH": - cmd_is_package_installed=["rpm", "-q"] + # 2) if dpkg not found search for apt + completed = SP.call(cmd_which_apt, stdout=devnull, stderr=SP.STDOUT) + if completed == 0 and linux == "DB": + cmd_is_package_installed = ["apt", "list", "--installed"] else: - # no package manager was found corresponding to dist_name - raise src.SatException(manager_msg_err) + # 3) if apt not found search for rpm (redhat) + completed=SP.call(cmd_which_rpm,stdout=devnull, stderr=SP.STDOUT) # only 3.8! ,capture_output=True) + if completed==0 and linux=="RH": + cmd_is_package_installed=["rpm", "-q"] + else: + # no package manager was found corresponding to dist_name + raise src.SatException(manager_msg_err) return cmd_is_package_installed def check_system_pkg(check_cmd,pkg): @@ -441,6 +447,21 @@ def check_system_pkg(check_cmd,pkg): except: msg_status=src.printcolors.printcError("KO") msg_status+=" (package is not installed!)\n" + elif check_cmd[0] == "dpkg-query": + # special treatment for dpkg-query + # some debian packages have version numbers in their name, we need to add a * + # also dpkg-query do not return status, we need to use grep + # and dpkg-query output is too messy for being used + cmd_is_package_installed[-1] = ( + cmd_is_package_installed[-1] + "*" + ) # we don't specify in pyconf the exact name because of version numbers + p = SP.Popen(cmd_is_package_installed, stdout=SP.PIPE, stderr=FNULL) + try: + output = SP.check_output(["grep", "^ii"], stdin=p.stdout) + msg_status = src.printcolors.printcSuccess("OK") + except SP.CalledProcessError: + msg_status = src.printcolors.printcError("KO") + msg_status += " (package is not installed!)\n" else: p=SP.Popen(cmd_is_package_installed, stdout=SP.PIPE, stderr=FNULL) output, err = p.communicate()