]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
spns #40790: on Debian distributions, use dpkg-query instead of apt to check system... 12/head
authorAymeric Sonolet <aymeric.sonolet@cea.fr>
Wed, 31 Jan 2024 11:57:38 +0000 (12:57 +0100)
committerNabil Ghodbane <nabil.ghodbane@cea.fr>
Wed, 31 Jan 2024 11:57:38 +0000 (12:57 +0100)
src/product.py
src/system.py

index 28948da38087ee5c4a7e8d74505908022fb6c1e1..a679e44817d9d767140fbeb15f83076b0ed1fe5c 100644 (file)
@@ -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)
index 17a7c06aa06b1ed038aeb353da8ec4ee1955ebcd..b00760840303f460d0f95d73b2d205ebca427420 100644 (file)
@@ -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()