From 186d215b8b7d90ccd34b1cb333081c49a1f631e6 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Thu, 25 Oct 2018 16:46:01 +0200 Subject: [PATCH] add def getProductNames using * or ? as wildcards like shell Linux for '--product' or '--info' options --- commands/config.py | 71 ++++++++++++------- .../alabaster/alabaster/static/custom.css | 26 ++++++- src/__init__.py | 22 ++++++ src/product.py | 37 ++++------ 4 files changed, 106 insertions(+), 50 deletions(-) mode change 120000 => 100644 doc/_themes/alabaster/alabaster/static/custom.css diff --git a/commands/config.py b/commands/config.py index d6b9dba..b5a3fbe 100644 --- a/commands/config.py +++ b/commands/config.py @@ -38,7 +38,7 @@ parser.add_option('g', 'debug', 'string', 'debug', _("Optional: print the debugging mode value of CONFIG_VARIABLE.")) parser.add_option('e', 'edit', 'boolean', 'edit', _("Optional: edit the product configuration file.")) -parser.add_option('i', 'info', 'string', 'info', +parser.add_option('i', 'info', 'list2', 'info', _("Optional: get information on a product.")) parser.add_option('l', 'list', 'boolean', 'list', _("Optional: list all available applications.")) @@ -734,12 +734,17 @@ def show_patchs(config, logger): ''' oneOrMore = False for product in sorted(config.APPLICATION.products): - product_info = src.product.get_product_config(config, product) - if src.product.product_has_patches(product_info): - oneOrMore = True - logger.write("%s:\n" % product, 1) - for i in product_info.patches: - logger.write(src.printcolors.printcInfo(" %s\n" % i), 1) + try: + product_info = src.product.get_product_config(config, product) + if src.product.product_has_patches(product_info): + oneOrMore = True + logger.write("%s:\n" % product, 1) + for i in product_info.patches: + logger.write(src.printcolors.printcInfo(" %s\n" % i), 1) + except Exception as e: + msg = "problem on product %s\n%s\n" % (product, str(e)) + logger.error(msg) + if oneOrMore: logger.write("\n", 1) else: @@ -754,18 +759,23 @@ def show_properties(config, logger): ''' oneOrMore = False for product in sorted(config.APPLICATION.products): - product_info = src.product.get_product_config(config, product) - done = False try: - for i in product_info.properties: - if not done: - logger.write("%s:\n" % product, 1) - done = True - oneOrMore = True - logger.write(src.printcolors.printcInfo(" %s\n" % i), 1) - except: + product_info = src.product.get_product_config(config, product) + done = False + try: + for i in product_info.properties: + if not done: + logger.write("%s:\n" % product, 1) + done = True + oneOrMore = True + logger.write(src.printcolors.printcInfo(" %s\n" % i), 1) + except Exception as e: + pass + except Exception as e: # logger.write(src.printcolors.printcInfo(" %s\n" % "no properties"), 1) - pass + msg = "problem on product %s\n%s\n" % (product, e) + logger.error(msg) + if oneOrMore: logger.write("\n", 1) else: @@ -932,16 +942,27 @@ def run(args, runner, logger): src.system.show_in_editor(editor, pyconf_path, logger) break - # case : give information about the product in parameter + # case : give information about the product(s) in parameter if options.info: - src.check_config_has_application(runner.cfg) - if options.info in runner.cfg.APPLICATION.products: - show_product_info(runner.cfg, options.info, logger) - # return + # DBG.write("products", sorted(runner.cfg.APPLICATION.products.keys()), True) + src.check_config_has_application(runner.cfg) + taggedProducts = src.getProductNames(runner.cfg, options.info, logger) + DBG.write("tagged products", sorted(taggedProducts)) + for prod in sorted(taggedProducts): + if prod in runner.cfg.APPLICATION.products: + try: + if len(taggedProducts) > 1: + logger.write("#################### ", 2) + show_product_info(runner.cfg, prod, logger) + except Exception as e: + msg = "problem on product %s\n%s\n" % (prod, str(e)) + logger.error(msg) + # return else: - msg = _("%s is not a product of %s.") % \ - (options.info, runner.cfg.VARS.application) - raise Exception(msg) + msg = _("%s is not a product of %s.\n") % \ + (prod, runner.cfg.VARS.application) + logger.warning(msg) + #raise Exception(msg) # case : copy an existing .pyconf # to ~/.salomeTools/Applications/LOCAL_.pyconf diff --git a/doc/_themes/alabaster/alabaster/static/custom.css b/doc/_themes/alabaster/alabaster/static/custom.css deleted file mode 120000 index 5e50e76..0000000 --- a/doc/_themes/alabaster/alabaster/static/custom.css +++ /dev/null @@ -1 +0,0 @@ -../../../../src/custom.css \ No newline at end of file diff --git a/doc/_themes/alabaster/alabaster/static/custom.css b/doc/_themes/alabaster/alabaster/static/custom.css new file mode 100644 index 0000000..a088ba6 --- /dev/null +++ b/doc/_themes/alabaster/alabaster/static/custom.css @@ -0,0 +1,25 @@ +/* This file is for theme alabaster custom. */ + +/* +http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html +set backquotes: ``text`` for code samples more color red +*/ +tt, code { + background-color: #ecf0f3; + color: #842; + /* padding: 1px 2px; */ +} + +/* +set 'Note:' etc size less than titles +*/ +div.admonition p.admonition-title { + font-family: {{ theme_head_font_family }}; + font-weight: normal; + font-size: 16px; + margin: 0 0 10px 0; + padding: 0; + line-height: 1; +} + + diff --git a/src/__init__.py b/src/__init__.py index 91dfc66..f2ad0ec 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -25,6 +25,7 @@ import os import shutil import errno import stat +import fnmatch from . import pyconf from . import architecture @@ -110,6 +111,27 @@ def get_cfg_param(config, param_name, default): return config[param_name] return default + +def getProductNames(cfg, wildcards, logger): + """get products names using * or ? as wildcards like shell Linux""" + res = [] + if type(wildcards) is list: + wilds = wildcards + else: + wilds = [wildcards] + products = cfg.APPLICATION.products.keys() + for prod in products: + for wild in wildcards: + filtered = fnmatch.filter([prod], wild) + # print("filtered", prod, wild, filtered) + if len(filtered) > 0: + res.append(prod) + break + if len(res) == 0: + logger.warning("Empty list of products, from %s" % wilds) + return res + + def print_info(logger, info): """\ Prints the tuples that are in info variable in a formatted way. diff --git a/src/product.py b/src/product.py index db231d2..42624ee 100644 --- a/src/product.py +++ b/src/product.py @@ -157,11 +157,10 @@ def get_product_config(config, product_name, with_install_dir=True): if not prod_pyconf_path: msg = _("""\ No definition found for the product %(1)s. -Please create a %(2)s.pyconf file somewhere in: -%(3)s""") % { - "1": product_name, - "2": product_name, - "3": config.PATHS.PRODUCTPATH } +Please create a %(1)s.pyconf file somewhere in: + %(2)s""") % { + "1": product_name, + "2": PP.pformat(config.PATHS.PRODUCTPATH) } else: msg = _("""\ No definition corresponding to the version %(1)s was found in the file: @@ -318,7 +317,10 @@ def get_product_section(config, product_name, version, section=None, verbose=Fal # if section is not None, try to get the corresponding section aProd = config.PRODUCTS[product_name] - versionMMP = VMMP.MinorMajorPatch(version) + try: + versionMMP = VMMP.MinorMajorPatch(version) + except: # example setuptools raise "minor in major_minor_patch is not integer: '0_6c11'" + versionMMP = None DBG.write("get_product_section for product %s '%s' as '%s'" % (product_name, version, versionMMP), (section, aProd.keys()), verbose) # DBG.write("yoo1", aProd, True) @@ -344,6 +346,7 @@ def get_product_section(config, product_name, version, section=None, verbose=Fal # Else, check if there is a description for multiple versions l_section_names = aProd.keys() l_section_ranges = [] + tagged = [] for name in l_section_names: # DBG.write("name", name,True) aRange = VMMP.getRange_majorMinorPatch(name) @@ -352,7 +355,6 @@ def get_product_section(config, product_name, version, section=None, verbose=Fal l_section_ranges.append((name, aRange)) if len(l_section_ranges) > 0: - tagged = [] for name, (vmin, vmax) in l_section_ranges: if versionMMP >= vmin and versionMMP <= vmax: tagged.append((name, [vmin, vmax])) @@ -370,21 +372,6 @@ def get_product_section(config, product_name, version, section=None, verbose=Fal prod_info.from_file = aProd.from_file return prod_info - """ - l_section_name = aProd.keys() - l_section_ranges = [section_name for section_name in l_section_name - if VERSION_DELIMITER in section_name] - for section_range in l_section_ranges: - minimum, maximum = section_range.split(VERSION_DELIMITER) - if (src.only_numbers(version) >= src.only_numbers(minimum) - and src.only_numbers(version) <= src.only_numbers(maximum)): - # returns specific information for the versions - prod_info = aProd[section_range] - prod_info.section = section_range - prod_info.from_file = aProd.from_file - return prod_info - """ - # Else, get the standard informations if "default" in aProd: # returns the generic information (given version not found) @@ -572,12 +559,14 @@ def get_products_list(options, cfg, logger): else: # if option --products, check that all products of the command line # are present in the application. - products = options.products + """products = options.products for p in products: if p not in cfg.APPLICATION.products: raise src.SatException(_("Product %(product)s " "not defined in application %(application)s") % - { 'product': p, 'application': cfg.VARS.application} ) + { 'product': p, 'application': cfg.VARS.application} )""" + + products = src.getProductNames(cfg, options.products, logger) # Construct the list of tuple containing # the products name and their definition -- 2.39.2