Salome HOME
sat #20460 : debug sat config --check_system on debian system
authorcrouzet <nicolas.crouzet@cea.fr>
Wed, 9 Dec 2020 14:24:28 +0000 (15:24 +0100)
committercrouzet <nicolas.crouzet@cea.fr>
Wed, 9 Dec 2020 14:24:28 +0000 (15:24 +0100)
src/system.py

index 672149d12cd50ae3986d55d9798e26b7dae6b94d..446074ef4c64d0edbf70a531cfb8889ebc6d0b06 100644 (file)
@@ -367,35 +367,43 @@ def check_system_pkg(check_cmd,pkg):
     :return: a string with package name with status un message
     '''
     # build command
+    FNULL = open(os.devnull, 'w')
     cmd_is_package_installed=[]
     for cmd in check_cmd:
         cmd_is_package_installed.append(cmd)
     cmd_is_package_installed.append(pkg)
+
+
     if check_cmd[0]=="apt":
         # special treatment for apt
-        # (some debian packages have version numbers in their name, and also
-        # apt do not return status)
+        # apt output is too messy for being used
+        # some debian packages have version numbers in their name, we need to add a *
+        # also apt do not return status, we need to use grep
+        # and apt output is too messy for being used 
         cmd_is_package_installed[-1]+="*" # we don't specify in pyconf the exact name because of version numbers
-        cmd_is_package_installed.append('|')
-        cmd_is_package_installed.append('grep') # add a grep to get an exit status
-        cmd_is_package_installed.append(cmd) 
-        
-    p=subprocess.Popen(cmd_is_package_installed, 
-                       stdout=subprocess.PIPE, 
-                       stderr=subprocess.PIPE)
-    output, err = p.communicate()
-
-    rc = p.returncode
-    if rc==0:
-        msg_status=src.printcolors.printcSuccess("OK")
-        if check_cmd[0]=="rpm": # apt output is too messy for being used
+        p=subprocess.Popen(cmd_is_package_installed,
+                           stdout=subprocess.PIPE,
+                           stderr=FNULL)
+        try:
+            output = subprocess.check_output(['grep', pkg], stdin=p.stdout)
+            msg_status=src.printcolors.printcSuccess("OK")
+        except:
+            msg_status=src.printcolors.printcError("KO")
+            msg_status+=" (package is not installed!)\n"
+    else:
+        p=subprocess.Popen(cmd_is_package_installed,
+                           stdout=subprocess.PIPE,
+                           stderr=FNULL)
+        output, err = p.communicate()
+        rc = p.returncode
+        if rc==0:
+            msg_status=src.printcolors.printcSuccess("OK")
             # in python3 output is a byte and should be decoded
             if isinstance(output, bytes):
                 output = output.decode("utf-8", "ignore")
             msg_status+=" (" + output.replace('\n',' ') + ")\n" # remove output trailing \n
-    else:
-        msg_status=src.printcolors.printcError("KO") 
-        msg_status+=" (package is not installed!)\n"
+        else:
+            msg_status=src.printcolors.printcError("KO")
+            msg_status+=" (package is not installed!)\n"
 
     return msg_status
-