]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
Replace apt list with dpkg-query for speed
authorSONOLET Aymeric <aymeric.sonolet@cea.fr>
Wed, 6 Dec 2023 11:45:42 +0000 (12:45 +0100)
committerSONOLET Aymeric <aymeric.sonolet@cea.fr>
Wed, 6 Dec 2023 11:45:42 +0000 (12:45 +0100)
src/product.py
src/system.py

index 28948da38087ee5c4a7e8d74505908022fb6c1e1..8a456eb3d6b604b9dc034bd7d1edf92d64b26363 100644 (file)
@@ -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)
index ae13e346f2253ddee0f5834469d31996e5751bf4..033ce06c7f221c9e02df5735373d633c3399794f 100644 (file)
@@ -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()