From 9c2dfb7930e778ab4d27f15c9a2223e3c149f952 Mon Sep 17 00:00:00 2001 From: Nicolas CROUZET - SFME/LGLS Date: Thu, 14 May 2020 11:02:45 +0200 Subject: [PATCH] sat #19109 : choix plus robuste du gestionnaire de paquets, et utilisation de platform.linux_distribution --- commands/config.py | 2 +- commands/source.py | 2 +- src/architecture.py | 8 ++++---- src/product.py | 2 +- src/system.py | 18 +++++++++++++----- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/commands/config.py b/commands/config.py index 927a889..f5e539c 100644 --- a/commands/config.py +++ b/commands/config.py @@ -794,7 +794,7 @@ def check_install_system(config, logger): ''' # get the command to use for checking the system dependencies # (either rmp or apt) - check_cmd=src.system.get_pkg_check_cmd() + check_cmd=src.system.get_pkg_check_cmd(config.VARS.dist_name) logger.write("\nCheck the system dependencies declared in the application\n",1) pkgmgr=check_cmd[0] run_dep_ko=[] # list of missing run time dependencies diff --git a/commands/source.py b/commands/source.py index 0f744a5..85ed4be 100644 --- a/commands/source.py +++ b/commands/source.py @@ -401,7 +401,7 @@ def get_product_sources(config, if product_info.get_source == "native": # for native products we check the corresponding system packages are installed logger.write("Native : Checking system packages are installed\n" , 3) - check_cmd=src.system.get_pkg_check_cmd() # (either rmp or apt) + check_cmd=src.system.get_pkg_check_cmd(config.VARS.dist_name) # (either rmp or apt) run_pkg,build_pkg=src.product.check_system_dep(check_cmd, product_info) result=True for pkg in run_pkg: diff --git a/src/architecture.py b/src/architecture.py index 7d66a03..7ca34e8 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -59,7 +59,7 @@ def get_distribution(codes): return "W" # else get linux distribution description from platform, and encode it with code - lin_distrib = platform.dist()[0].lower() + lin_distrib = platform.linux_distribution()[0].lower() distrib="not found" for dist in codes: if dist in lin_distrib: @@ -76,9 +76,9 @@ def get_version_XY(): """ Return major and minor version of the distribution from a CentOS example, returns '7.6' - extracted from platform.dist() + extracted from platform.linux_distribution() """ - dist_version=platform.dist()[1].split('.') + dist_version=platform.linux_distribution()[1].split('.') if len(dist_version)==1: version = dist_version[0] else: @@ -102,7 +102,7 @@ def get_distrib_version(distrib): return platform.release() # get version from platform - dist_version=platform.dist()[1].split('.') + dist_version=platform.linux_distribution()[1].split('.') # encode it (conform to src/internal_config/distrib.pyconf VERSIONS dist if distrib == "CO": diff --git a/src/product.py b/src/product.py index 7323a28..32af959 100644 --- a/src/product.py +++ b/src/product.py @@ -839,7 +839,7 @@ def check_installation(config, product_info): if product_is_native(product_info): # check a system product - check_cmd=src.system.get_pkg_check_cmd() + check_cmd=src.system.get_pkg_check_cmd(config.VARS.dist_name) run_pkg,build_pkg=src.product.check_system_dep(check_cmd, product_info) build_dep_ko=[] for pkg in build_pkg: diff --git a/src/system.py b/src/system.py index 3a87433..3360807 100644 --- a/src/system.py +++ b/src/system.py @@ -324,24 +324,32 @@ def svn_extract(user, stderr=subprocess.STDOUT) return (res == 0) -def get_pkg_check_cmd(): +def get_pkg_check_cmd(dist_name): '''Build the command to use for checking if a linux package is installed or not.''' + + if dist_name in ["CO","FD","MG","MD","CO","OS"]: # linux using rpm + linux="RH" + manager_msg_err="Error : command failed because sat was not able to find apt command" + else: + 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"] with open(os.devnull, 'w') as devnull: # 1) we search for apt (debian based systems) completed=subprocess.call(cmd_which_apt,stdout=devnull, stderr=subprocess.STDOUT) - if completed==0: + if completed==0 and linux=="DB": cmd_is_package_installed=["apt", "list", "--installed"] else: # 2) if apt not found search for rpm (redhat) completed=subprocess.call(cmd_which_rpm,stdout=devnull, stderr=subprocess.STDOUT) # only 3.8! ,capture_output=True) - if completed==0: + if completed==0 and linux=="RH": cmd_is_package_installed=["rpm", "-q"] else: - # no package manager was found - raise src.SatException("Error : command failed because sat was not able to find apt or rpm") + # 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): -- 2.39.2