_("Optional: synthetic list of all install directories in the application"))
parser.add_option('', 'show_properties', 'boolean', 'show_properties',
_("Optional: synthetic list of all properties used in the application"))
+parser.add_option('', 'check_system', 'boolean', 'check_system',
+ _("Optional: check if system products are installed"))
parser.add_option('c', 'copy', 'boolean', 'copy',
_("""Optional: copy a config file to the personal config files directory.
WARNING: the included files are not copied.
else:
logger.write("No patchs found\n", 1)
+def check_install_system(config, logger):
+ '''Check the installation of all (declared) system products
+
+ :param config Config: the global configuration.
+ :param logger Logger: The logger instance to use for the display
+ '''
+ # get the command to use for checking the system dependencies
+ # (either rmp or apt)
+ check_cmd=src.system.get_pkg_check_cmd()
+ logger.write("\nCheck the system dependencies declared in the application\n",1)
+ pkgmgr=check_cmd[0]
+ for product in sorted(config.APPLICATION.products):
+ try:
+ product_info = src.product.get_product_config(config, product)
+ if src.product.product_is_native(product_info):
+ # if the product is native, get (in two dictionnaries the runtime and compile time
+ # system dependencies with the status (OK/KO)
+ run_pkg,build_pkg=src.product.check_system_dep(check_cmd, product_info)
+ #logger.write("\n*** %s ***\n" % product, 1)
+ for pkg in run_pkg:
+ logger.write(run_pkg[pkg], 1)
+ for pkg in build_pkg:
+ logger.write(build_pkg[pkg], 1)
+ # logger.write(src.printcolors.printcInfo(" %s\n" % i), 1)
+
+ except Exception as e:
+ msg = "problem with the check of system prerequisite %s\n%s\n" % (product, str(e))
+ logger.error(msg)
+
def show_install_dir(config, logger):
'''Prints all the used installed directories in the application.
logger.write("\n", 2, False)
show_properties(runner.cfg, logger)
+ # check system prerequisites
+ if options.check_system:
+ check_install_system(runner.cfg, logger)
+ pass
result = eval(eval_expression)
return result
+def check_system_dep(check_cmd, product_info):
+ """Search for system dependencies, check if installed
+ :param check_cmd Config: The command to use for checking (rpm/apt)
+ :param product_info Config: The configuration specific to the product
+ :rtype: two dictionnaries for runtime and compile time dependencies with text status
+ """
+ runtime_dep={}
+ build_dep={}
+ if "system_info" in product_info:
+ if check_cmd[0]=="rpm":
+ if "rpm" in product_info.system_info:
+ for pkg in product_info.system_info.rpm:
+ runtime_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg)
+ if "rpm_dev" in product_info.system_info:
+ for pkg in product_info.system_info.rpm_dev:
+ build_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg)
+ if check_cmd[0]=="apt":
+ if "apt" in product_info.system_info:
+ for pkg in product_info.system_info.apt:
+ runtime_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg)
+ if "apt_dev" in product_info.system_info:
+ for pkg in product_info.system_info.apt_dev:
+ build_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg)
+ #for pkg in runtime_dep:
+ # print "CNC check for ", pkg
+ # runtime_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg)
+ #for pkg in build_dep:
+ # build_dep[pkg]=src.system.check_system_pkg(check_cmd,pkg)
+ #print "CNC runtime_dep=", runtime_dep
+ return runtime_dep,build_dep
def get_product_components(product_info):
stdout=logger.logTxtFile,
stderr=subprocess.STDOUT)
return (res == 0)
+
+def get_pkg_check_cmd():
+ '''Build the command to use for checking if a linux package is installed or not.'''
+ # 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:
+ 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:
+ 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")
+ return cmd_is_package_installed
+
+def check_system_pkg(check_cmd,pkg):
+ '''Check if a package is installed
+ :param check_cmd list: the list of command to use system package manager
+ :param user str: the pkg name to check
+ :rtype: str
+ :return: a string with package name with status un message
+ '''
+ # build command
+ 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)
+ 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=" - "+pkg + " : " + src.printcolors.printcSuccess("OK") +\
+ " (" + output.replace('\n',' ') + ")\n" # remove output trailing \n
+ else:
+ msg_status=" - "+pkg + " : " + src.printcolors.printcError("KO") +\
+ " (package is not installed!)\n"
+ return msg_status
+