From 4ea72334ff7a3f01069e877569200c1ee82ffc71 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Mon, 6 Jun 2016 16:37:19 +0200 Subject: [PATCH] Add info option to config command --- commands/config.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++ src/fileEnviron.py | 52 +++++++++++++++++++++++++ 2 files changed, 147 insertions(+) diff --git a/commands/config.py b/commands/config.py index 6ca161e..e6f59ee 100644 --- a/commands/config.py +++ b/commands/config.py @@ -35,6 +35,8 @@ parser.add_option('v', 'value', 'string', 'value', _("print the value of CONFIG_VARIABLE.")) parser.add_option('e', 'edit', 'boolean', 'edit', _("edit the product configuration file.")) +parser.add_option('i', 'info', 'string', 'info', + _("get information on a product.")) parser.add_option('l', 'list', 'boolean', 'list', _("list all available applications.")) parser.add_option('c', 'copy', 'boolean', 'copy', @@ -415,6 +417,92 @@ class ConfigManager: raise src.SatException(_("Error in get_user_config_file: " "missing user config file path")) return self.user_config_file_path + +def check_path(path, ext=[]): + # check if file exists + if not os.path.exists(path): + return "'%s'" % path + " " + src.printcolors.printcError(_("** not found")) + + # check extension + if len(ext) > 0: + fe = os.path.splitext(path)[1].lower() + if fe not in ext: + return "'%s'" % path + " " + src.printcolors.printcError(_("** bad extension")) + + return path + +def show_product_info(config, name, logger): + logger.write(_("%s is a product\n") % src.printcolors.printcLabel(name), 2) + pinfo = src.product.get_product_config(config, name) + + ptype = src.get_cfg_param(pinfo, "type", "") + src.printcolors.print_value(logger, "type", ptype, 2) + if "opt_depend" in pinfo: + src.printcolors.print_value(logger, "depends on", ', '.join(pinfo.depend), 2) + + if "opt_depend" in pinfo: + src.printcolors.print_value(logger, "optional", ', '.join(pinfo.opt_depend), 2) + + # information on prepare + logger.write("\n", 2) + logger.write(src.printcolors.printcLabel("prepare:") + "\n", 2) + + is_dev = src.product.product_is_dev(pinfo) + method = pinfo.get_source + if is_dev: + method += " (dev)" + src.printcolors.print_value(logger, "get method", method, 2) + + if method == 'cvs': + src.printcolors.print_value(logger, "server", pinfo.cvs_info.server, 2) + src.printcolors.print_value(logger, "base module", pinfo.cvs_info.module_base, 2) + src.printcolors.print_value(logger, "source", pinfo.cvs_info.source, 2) + src.printcolors.print_value(logger, "tag", pinfo.cvs_info.tag, 2) + + elif method == 'svn': + src.printcolors.print_value(logger, "repo", pinfo.svn_info.repo, 2) + + elif method == 'git': + src.printcolors.print_value(logger, "repo", pinfo.git_info.repo, 2) + src.printcolors.print_value(logger, "tag", pinfo.git_info.tag, 2) + + elif method == 'archive': + src.printcolors.print_value(logger, "get from", check_path(pinfo.archive_info.archive_name), 2) + + if 'patches' in pinfo: + for patch in pinfo.patches: + src.printcolors.print_value(logger, "patch", check_path(patch), 2) + + if src.product.product_is_fixed(pinfo): + src.printcolors.print_value(logger, "install_dir", check_path(pinfo.install_dir), 2) + + if src.product.product_is_native(pinfo) or src.product.product_is_fixed(pinfo): + return + + # information on compilation + logger.write("\n", 2) + logger.write(src.printcolors.printcLabel("compile:") + "\n", 2) + src.printcolors.print_value(logger, "compilation method", pinfo.build_source, 2) + + if 'nb_proc' in pinfo: + src.printcolors.print_value(logger, "make -j", pinfo.nb_proc, 2) + + src.printcolors.print_value(logger, "source dir", check_path(pinfo.source_dir), 2) + if 'install_dir' in pinfo: + src.printcolors.print_value(logger, "build dir", check_path(pinfo.build_dir), 2) + src.printcolors.print_value(logger, "install dir", check_path(pinfo.install_dir), 2) + else: + logger.write(" " + src.printcolors.printcWarning(_("no install dir")) + "\n", 2) + + # information on environment + logger.write("\n", 2) + logger.write(src.printcolors.printcLabel("environ :") + "\n", 2) + if "environ" in pinfo and "env_script" in pinfo.environ: + src.printcolors.print_value(logger, "script", check_path(pinfo.environ.env_script), 2) + + zz = src.environment.SalomeEnviron(config, src.fileEnviron.ScreenEnviron(logger), False) + zz.set_python_libdirs() + zz.set_a_product(name, logger) def print_value(config, path, show_label, logger, level=0, show_full_path=False): @@ -558,6 +646,13 @@ def run(args, runner, logger): src.system.show_in_editor(editor, pyconf_path, logger) break + # case : give information about the product in parameter + elif options.info: + if options.info in runner.cfg.APPLICATION.products: + show_product_info(runner.cfg, options.info, logger) + return + raise src.SatException(_("%(product_name)s is not a product of %(application_name)s.") % {'product_name' : options.info, 'application_name' : runner.cfg.VARS.application}) + # case : copy an existing .pyconf # to ~/.salomeTools/Applications/LOCAL_.pyconf elif options.copy: diff --git a/src/fileEnviron.py b/src/fileEnviron.py index aac1488..3ed76b3 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -568,6 +568,58 @@ class LauncherFileEnviron: """ return +class ScreenEnviron(FileEnviron): + def __init__(self, output, environ=None): + self._do_init(output, environ) + self.defined = {} + + def add_line(self, number): + pass + + def add_comment(self, comment): + pass + + def add_echo(self, text): + pass + + def add_warning(self, warning): + pass + + def write(self, command, name, value, sign="="): + import src + self.output.write(" %s%s %s %s %s\n" % \ + (src.printcolors.printcLabel(command), + " " * (12 - len(command)), + src.printcolors.printcInfo(name), sign, value)) + + def is_defined(self, name): + return self.defined.has_key(name) + + def get(self, name): + return "${%s}" % name + + def set(self, name, value): + self.write("set", name, value) + self.defined[name] = value + + def prepend(self, name, value, sep=":"): + if isinstance(value, list): + value = sep.join(value) + value = value + sep + self.get(name) + self.write("prepend", name, value) + + def append(self, name, value, sep=":"): + if isinstance(value, list): + value = sep.join(value) + value = self.get(name) + sep + value + self.write("append", name, value) + + def command_value(self, key, command): + pass + + def run_env_script(self, module, script): + self.write("load", script, "", sign="") + # The SALOME launcher template withProfile = """#! /usr/bin/env python -- 2.39.2