From a9ff7f3e5f15fe7db2e9adbad6594db7b77c5c89 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Fri, 14 Dec 2018 10:57:30 +0100 Subject: [PATCH] add dist_ref --- commands/config.py | 39 ++++++++++++++------------------------ src/architecture.py | 46 ++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 48 deletions(-) diff --git a/commands/config.py b/commands/config.py index 21f861e..d2fc640 100644 --- a/commands/config.py +++ b/commands/config.py @@ -51,8 +51,8 @@ parser.add_option('', 'show_properties', 'boolean', 'show_properties', _("Optional: synthetic list of all properties used in the application")) parser.add_option('c', 'copy', 'boolean', 'copy', _("""Optional: copy a config file to the personal config files directory. -\tWARNING the included files are not copied. -\tIf a name is given the new config file takes the given name.""")) +WARNING: the included files are not copied. +If a name is given the new config file takes the given name.""")) parser.add_option('n', 'no_label', 'boolean', 'no_label', _("Internal use: do not print labels, Works only with --value and --list.")) parser.add_option('', 'completion', 'boolean', 'completion', @@ -118,45 +118,37 @@ class ConfigManager: if datadir is not None: var['datadir'] = datadir - var['personalDir'] = os.path.join(os.path.expanduser('~'), - '.salomeTools') + var['personalDir'] = os.path.join(os.path.expanduser('~'), '.salomeTools') src.ensure_path_exists(var['personalDir']) - var['personal_applications_dir'] = os.path.join(var['personalDir'], - "Applications") + var['personal_applications_dir'] = os.path.join(var['personalDir'], "Applications") src.ensure_path_exists(var['personal_applications_dir']) - var['personal_products_dir'] = os.path.join(var['personalDir'], - "products") + var['personal_products_dir'] = os.path.join(var['personalDir'], "products") src.ensure_path_exists(var['personal_products_dir']) - var['personal_archives_dir'] = os.path.join(var['personalDir'], - "Archives") + var['personal_archives_dir'] = os.path.join(var['personalDir'], "Archives") src.ensure_path_exists(var['personal_archives_dir']) - var['personal_jobs_dir'] = os.path.join(var['personalDir'], - "Jobs") + var['personal_jobs_dir'] = os.path.join(var['personalDir'], "Jobs") src.ensure_path_exists(var['personal_jobs_dir']) - var['personal_machines_dir'] = os.path.join(var['personalDir'], - "Machines") + var['personal_machines_dir'] = os.path.join(var['personalDir'], "Machines") src.ensure_path_exists(var['personal_machines_dir']) # read linux distributions dictionary - distrib_cfg = src.pyconf.Config(os.path.join(var['srcDir'], - 'internal_config', - 'distrib.pyconf')) + distrib_cfg = src.pyconf.Config(os.path.join(var['srcDir'], 'internal_config', 'distrib.pyconf')) # set platform parameters - dist_name = src.architecture.get_distribution( - codes=distrib_cfg.DISTRIBUTIONS) - dist_version = src.architecture.get_distrib_version(dist_name, - codes=distrib_cfg.VERSIONS) + dist_name = src.architecture.get_distribution(codes=distrib_cfg.DISTRIBUTIONS) + dist_version = src.architecture.get_distrib_version(dist_name, codes=distrib_cfg.VERSIONS) + dist_version_full = src.architecture.get_infosys() dist = dist_name + dist_version var['dist_name'] = dist_name var['dist_version'] = dist_version var['dist'] = dist + var['dist_ref'] = dist_name + dist_version_full var['python'] = src.architecture.get_python_version() var['nb_proc'] = src.architecture.get_nb_proc() @@ -225,7 +217,7 @@ class ConfigManager: # ===================================================================== # create VARS section var = self._create_vars(application=application, command=command, datadir=datadir) - print("create_vars:\n%s" % PP.pformat(var)) + DBG.write("create_vars", var, DBG.isDeveloper()) # add VARS to config cfg.VARS = src.pyconf.Mapping(cfg) @@ -893,9 +885,6 @@ def description(): def run(args, runner, logger): '''method that is called when salomeTools is called with config parameter. ''' - import src.architecture as ARCH - print("get_infosys %s " % PP.pformat(ARCH.get_infosys())) - # Parse the options (options, args) = parser.parse_args(args) diff --git a/src/architecture.py b/src/architecture.py index de8663d..a638427 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -58,16 +58,14 @@ def _lsb_release(args): path = lsb_path + ":" + path from subprocess import Popen, PIPE - res = Popen(['lsb_release', args], env={'PATH': path}, - stdout=PIPE).communicate()[0][:-1] + res = Popen(['lsb_release', args], env={'PATH': path}, stdout=PIPE).communicate()[0][:-1] # in case of python3, convert byte to str if isinstance(res, bytes): res = res.decode() return res except OSError: sys.stderr.write(_(u"lsb_release not installed\n")) - sys.stderr.write(_(u"You can define $LSB_PATH to give" - " the path to lsb_release\n")) + sys.stderr.write(_(u"You can define $LSB_PATH to give the path to lsb_release\n")) sys.exit(-1) def get_distribution(codes): @@ -87,30 +85,35 @@ def get_distribution(codes): distrib = codes[distrib] else: sys.stderr.write(_(u"Unknown distribution: '%s'\n") % distrib) - sys.stderr.write(_(u"Please add your distribution to" - " src/internal_config/distrib.pyconf\n")) + sys.stderr.write(_(u"Please add your distribution to src/internal_config/distrib.pyconf\n")) sys.exit(-1) return distrib -# Added by Lioka RAZAFINDRAZAKA -# and functions are used to get info from shell command -def run_shell(sh_cmd, pipe=True): - import subprocess - if pipe: popen = subprocess.Popen(sh_cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - else: popen = subprocess.Popen(sh_cmd, shell=True, close_fds=True) - out_put = popen.communicate() - return out_put[0], out_put[1], popen.returncode - def get_infosys(): - import re, socket + """ + from a CentOS example, + returns '7.6' from command 'lsb_release -ds' + extracted from 'CentOS Linux release 7.6.1810 (Core)' + and also for RedHat fedora etc. + """ + import re osys = "" version = "" architecture = "" osys_value = "Unknown" - os_dict = {"mandrivalinux":"MD", "centos":"CO", "RedHatEnterpriseServer":"CO", "RedHatEnterpriseWorkstation":"CO", "fedora":"FD", "ubuntu":"UB", "debian":"DB", "mageia":"MG",} - lsb_cmd = "lsb_release -ds" - output, errdata, return_code = run_shell(lsb_cmd) + os_dict = {"mandrivalinux":"MD", + "centos":"CO", + "RedHatEnterpriseServer":"CO", + "RedHatEnterpriseWorkstation":"CO", + "fedora":"FD", + "ubuntu":"UB", + "debian":"DB", + "mageia":"MG",} + # lsb_cmd = "lsb_release -ds" + args = "-ds" + output = _lsb_release(args) + # print("lsb_release output %s" % output) regexp = r"(^[0-9]+([.]?[0-9]+)+)" for an_item in output.replace('"','').split(): if re.match(regexp, an_item) is not None and not version: @@ -121,10 +124,7 @@ def get_infosys(): osys = an_item osys_value = os_dict[sub_item] if version and osys: break - import platform - architecture = platform.architecture()[0][:2] - infosys = "_".join([osys,version,architecture,"bits",socket.gethostname(),osys_value+version]) - return version, infosys + return version def get_distrib_version(distrib, codes): '''Gets the version of the distribution -- 2.30.2