From 0d9ec1f0af5397f15ca60bbf5283bf444c318750 Mon Sep 17 00:00:00 2001 From: SONOLET Aymeric Date: Wed, 6 Dec 2023 12:45:42 +0100 Subject: [PATCH] Replace apt list with dpkg-query for speed --- src/product.py | 23 ++++++++++++----------- src/system.py | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/product.py b/src/product.py index 28948da..8a456eb 100644 --- a/src/product.py +++ b/src/product.py @@ -896,17 +896,17 @@ def check_installation(config, product_info): build_dep_ko=[] for pkg in build_pkg: if "KO" in build_pkg[pkg]: - build_dep_ko.append(pkg) + build_dep_ko.append(pkg) if build_dep_ko: - # the product is not installed : display message and return error status - msg="Please install them with %s before compiling salome" % check_cmd[0] - print("\nmissing compile time dependencies : ") - for md in build_dep_ko: - print(md) - print(msg) - return False - else: - return True + # the product is not installed : display message and return error status + msg="Please install them with %s before compiling salome" % check_cmd[0] + print(build_pkg) + print("\nmissing compile time dependencies : ") + for md in build_dep_ko: + print(md) + print(msg) + return False + return True install_dir = product_info.install_dir if src.product.product_is_fixed(product_info): @@ -1312,7 +1312,8 @@ 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": + else: 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 ae13e34..033ce06 100644 --- a/src/system.py +++ b/src/system.py @@ -469,12 +469,14 @@ def get_pkg_check_cmd(dist_name): # 1- search for an installed package manager (rpm on rh, apt on db) cmd_which_rpm=["which", "rpm"] - cmd_which_apt=["which", "apt"] + # cmd_which_apt=["which", "apt"] + cmd_which_apt=["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) if completed==0 and linux=="DB": - cmd_is_package_installed=["apt", "list", "--installed"] + # 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) @@ -514,6 +516,19 @@ 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() -- 2.39.2