From 6cb6aac483a7d637f972f70e10500411e4cecfaf Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Mon, 15 Oct 2018 14:26:53 +0200 Subject: [PATCH] #8577 extension du domaine des properties --- commands/check.py | 37 +----------------- commands/clean.py | 58 +--------------------------- commands/compile.py | 61 +----------------------------- commands/configure.py | 34 +---------------- commands/make.py | 37 +----------------- commands/makeinstall.py | 34 +---------------- commands/patch.py | 15 +------- commands/prepare.py | 57 +--------------------------- commands/script.py | 37 +----------------- commands/source.py | 15 +------- src/options.py | 69 +++++++++++++++++++++++----------- src/product.py | 83 ++++++++++++++++++++++++++++++++++++++++- 12 files changed, 141 insertions(+), 396 deletions(-) diff --git a/commands/check.py b/commands/check.py index 4a490a4..d4c78b2 100644 --- a/commands/check.py +++ b/commands/check.py @@ -28,41 +28,6 @@ parser.add_option('p', 'products', 'list2', 'products', CHECK_PROPERTY = "has_unit_tests" -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param cfg Config: The global configuration - :param logger Logger: The logger instance to use for the display and - logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - products_infos = [pi for pi in products_infos if not( - src.product.product_is_native(pi[1]) or - src.product.product_is_fixed(pi[1]))] - - return products_infos def log_step(logger, header, step): logger.write("\r%s%s" % (header, " " * 20), 3) @@ -218,7 +183,7 @@ def run(args, runner, logger): src.check_config_has_application( runner.cfg ) # Get the list of products to treat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Print some informations logger.write(_('Executing the check command in the build ' diff --git a/commands/clean.py b/commands/clean.py index b12182b..3204c0f 100644 --- a/commands/clean.py +++ b/commands/clean.py @@ -27,17 +27,13 @@ try: except NameError: pass -PROPERTY_EXPRESSION = "^.+:.+$" # Define all possible option for the clean command : sat clean parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('Optional: Products to clean. This option can be' ' passed several time to clean several products.')) -parser.add_option('', 'properties', 'string', 'properties', - _('Optional: Filter the products by their properties.\n\tSyntax: ' - '--properties :')) -parser.add_option('s', 'sources', 'boolean', 'sources', +parser.add_option('s', 'sources', 'boolean', 'sources', _("Optional: Clean the product source directories.")) parser.add_option('b', 'build', 'boolean', 'build', _("Optional: Clean the product build directories.")) @@ -48,46 +44,6 @@ parser.add_option('a', 'all', 'boolean', 'all', parser.add_option('', 'sources_without_dev', 'boolean', 'sources_without_dev', _("Optional: do not clean the products in development mode.")) -def get_products_list(options, cfg, logger): - """\ - method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param config Config: The global configuration - :param logger Logger: The logger instance to use for the display and logging - :return: The list of (product name, product_informations). - :rtype: List - """ - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - # if the property option was passed, filter the list - if options.properties: - [prop, value] = options.properties.split(":") - products_infos = [(p_name, p_info) for - (p_name, p_info) in products_infos - if "properties" in p_info and - prop in p_info.properties and - p_info.properties[prop] == value] - - return products_infos def get_source_directories(products_infos, without_dev): """\ @@ -197,19 +153,9 @@ def run(args, runner, logger): # check that the command has been called with an application src.check_config_has_application( runner.cfg ) - # Verify the --properties option - if options.properties: - oExpr = re.compile(PROPERTY_EXPRESSION) - if not oExpr.search(options.properties): - msg = _('WARNING: the "--properties" options must have the ' - 'following syntax:\n--properties :') - logger.write(src.printcolors.printcWarning(msg), 1) - logger.write("\n", 1) - options.properties = None - # Get the list of products to threat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Construct the list of directories to suppress l_dir_to_suppress = [] diff --git a/commands/compile.py b/commands/compile.py index 31b8ede..1a80f40 100644 --- a/commands/compile.py +++ b/commands/compile.py @@ -28,16 +28,12 @@ try: except NameError: pass -PROPERTY_EXPRESSION = "^.+:.+$" # Define all possible option for the compile command : sat compile parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('Optional: products to compile. This option can be' ' passed several time to compile several products.')) -parser.add_option('', 'properties', 'string', 'properties', - _('Optional: Filter the products by their properties.\n\tSyntax: ' - '--properties :')) parser.add_option('', 'with_fathers', 'boolean', 'fathers', _("Optional: build all necessary products to the given product (KERNEL is " "build before building GUI)."), False) @@ -63,51 +59,6 @@ parser.add_option('', 'check', 'boolean', 'check', _( parser.add_option('', 'clean_build_after', 'boolean', 'clean_build_after', _('Optional: remove the build directory after successful compilation'), False) -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param cfg Config: The global configuration - :param logger Logger: The logger instance to use for the display and - logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - # if the property option was passed, filter the list - if options.properties: - [prop, value] = options.properties.split(":") - products_infos = [(p_name, p_info) for - (p_name, p_info) in products_infos - if "properties" in p_info and - prop in p_info.properties and - p_info.properties[prop] == value] - - - # get rid of fixed products - products_infos = [pi for pi in products_infos if not( - src.product.product_is_fixed(pi[1]))] - - return products_infos def get_children(config, p_name_p_info): l_res = [] @@ -693,16 +644,6 @@ def run(args, runner, logger): # check that the command has been called with an application src.check_config_has_application( runner.cfg ) - # Verify the --properties option - if options.properties: - oExpr = re.compile(PROPERTY_EXPRESSION) - if not oExpr.search(options.properties): - msg = _('WARNING: the "--properties" options must have the ' - 'following syntax:\n--properties :') - logger.write(src.printcolors.printcWarning(msg), 1) - logger.write("\n", 1) - options.properties = None - # Print some informations logger.write(_('Executing the compile commands in the build ' 'directories of the products of ' @@ -718,7 +659,7 @@ def run(args, runner, logger): src.print_info(logger, info) # Get the list of products to treat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) if options.fathers: # Extend the list with all recursive dependencies of the given products diff --git a/commands/configure.py b/commands/configure.py index 2fa43e7..688fff0 100644 --- a/commands/configure.py +++ b/commands/configure.py @@ -28,38 +28,6 @@ parser.add_option('p', 'products', 'list2', 'products', parser.add_option('o', 'option', 'string', 'option', _('Optional: Option to add to the configure or cmake command.'), "") -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param cfg Config: The global configuration - :param logger Logger: The logger instance to use for the display and logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - products_infos = [pi for pi in products_infos if not(src.product.product_is_native(pi[1]) or src.product.product_is_fixed(pi[1]))] - - return products_infos def log_step(logger, header, step): logger.write("\r%s%s" % (header, " " * 20), 3) @@ -195,7 +163,7 @@ def run(args, runner, logger): src.check_config_has_application( runner.cfg ) # Get the list of products to treat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Print some informations logger.write(_('Configuring the sources of the application %s\n') % diff --git a/commands/make.py b/commands/make.py index 45b3155..6682f81 100644 --- a/commands/make.py +++ b/commands/make.py @@ -29,41 +29,6 @@ parser.add_option('p', 'products', 'list2', 'products', parser.add_option('o', 'option', 'string', 'option', _('Optional: Option to add to the make command.'), "") -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param cfg Config: The global configuration - :param logger Logger: The logger instance to use for the display and - logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - products_infos = [pi for pi in products_infos if not( - src.product.product_is_native(pi[1]) or - src.product.product_is_fixed(pi[1]))] - - return products_infos def log_step(logger, header, step): logger.write("\r%s%s" % (header, " " * 20), 3) @@ -216,7 +181,7 @@ def run(args, runner, logger): src.check_config_has_application( runner.cfg ) # Get the list of products to treat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Print some informations logger.write(_('Executing the make command in the build ' diff --git a/commands/makeinstall.py b/commands/makeinstall.py index 2e8e8fd..ff13382 100644 --- a/commands/makeinstall.py +++ b/commands/makeinstall.py @@ -26,38 +26,6 @@ parser.add_option('p', 'products', 'list2', 'products', _('Optional: products to install. This option can be' ' passed several time to install several products.')) -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param cfg Config: The global configuration - :param logger Logger: The logger instance to use for the display and logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - products_infos = [pi for pi in products_infos if not(src.product.product_is_native(pi[1]) or src.product.product_is_fixed(pi[1]))] - - return products_infos def log_step(logger, header, step): logger.write("\r%s%s" % (header, " " * 20), 3) @@ -180,7 +148,7 @@ def run(args, runner, logger): src.check_config_has_application( runner.cfg ) # Get the list of products to treat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Print some informations logger.write(_('Executing the make install command in the build directories of the application %s\n') % diff --git a/commands/patch.py b/commands/patch.py index 974c28a..ac106df 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -28,9 +28,6 @@ parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('Optional: products to get the sources. This option can be' ' passed several time to get the sources of several products.')) -parser.add_option('', 'properties', 'string', 'properties', - _('Optional: Filter the products by their properties.\n\tSyntax: ' - '--properties :')) def apply_patch(config, product_info, max_product_name_len, logger): '''The method called to apply patches on a product @@ -144,16 +141,6 @@ def run(args, runner, logger): # check that the command has been called with an application src.check_config_has_application( runner.cfg ) - # Verify the --properties option - if options.properties: - oExpr = re.compile(prepare.PROPERTY_EXPRESSION) - if not oExpr.search(options.properties): - msg = _('WARNING: the "--properties" options must have the ' - 'following syntax:\n--properties :') - logger.write(src.printcolors.printcWarning(msg), 1) - logger.write("\n", 1) - options.properties = None - # Print some informations logger.write('Patching sources of the application %s\n' % src.printcolors.printcLabel(runner.cfg.VARS.application), 1) @@ -163,7 +150,7 @@ def run(args, runner, logger): logger.write("\n", 2, False) # Get the products list with products informations regarding the options - products_infos = prepare.get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Get the maximum name length in order to format the terminal display max_product_name_len = 1 diff --git a/commands/prepare.py b/commands/prepare.py index eb05265..cb630e5 100644 --- a/commands/prepare.py +++ b/commands/prepare.py @@ -23,60 +23,17 @@ import pprint as PP import src import src.debug as DBG -PROPERTY_EXPRESSION = "^.+:.+$" # Define all possible option for prepare command : sat prepare parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('Optional: products to prepare. This option can be' ' passed several time to prepare several products.')) -parser.add_option('', 'properties', 'string', 'properties', - _('Optional: Filter the products by their properties.\n\tSyntax: ' - '--properties :')) -parser.add_option('f', 'force', 'boolean', 'force', +parser.add_option('f', 'force', 'boolean', 'force', _("Optional: force to prepare the products in development mode.")) parser.add_option('', 'force_patch', 'boolean', 'force_patch', _("Optional: force to apply patch to the products in development mode.")) -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param config Config: The global configuration - :param logger Logger: The logger instance to use for the display and logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - # if the property option was passed, filter the list - if options.properties: - [prop, value] = options.properties.split(":") - products_infos = [(p_name, p_info) for - (p_name, p_info) in products_infos - if "properties" in p_info and - prop in p_info.properties and - p_info.properties[prop] == value] - - return products_infos def find_products_already_getted(l_products): '''function that returns the list of products that have an existing source @@ -129,17 +86,7 @@ def run(args, runner, logger): # check that the command has been called with an application src.check_config_has_application( runner.cfg ) - # Verify the --properties option - if options.properties: - oExpr = re.compile(PROPERTY_EXPRESSION) - if not oExpr.search(options.properties): - msg = _('WARNING: the "--properties" options must have the ' - 'following syntax:\n--properties :') - logger.write(src.printcolors.printcWarning(msg), 1) - logger.write("\n", 1) - options.properties = None - - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Construct the arguments to pass to the clean, source and patch commands args_appli = runner.cfg.VARS.application + " " # useful whitespace diff --git a/commands/script.py b/commands/script.py index 688ec71..bd2ee40 100644 --- a/commands/script.py +++ b/commands/script.py @@ -31,41 +31,6 @@ parser.add_option('', 'nb_proc', 'int', 'nb_proc', 'if you want this option to work.\n\tThe $MAKE_OPTIONS has to be ' 'used.'), 0) -def get_products_list(options, cfg, logger): - '''method that gives the product list with their informations from - configuration regarding the passed options. - - :param options Options: The Options instance that stores the commands - arguments - :param cfg Config: The global configuration - :param logger Logger: The logger instance to use for the display and - logging - :return: The list of (product name, product_informations). - :rtype: List - ''' - # Get the products to be prepared, regarding the options - if options.products is None: - # No options, get all products sources - products = cfg.APPLICATION.products - else: - # if option --products, check that all products of the command line - # are present in the application. - 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} ) - - # Construct the list of tuple containing - # the products name and their definition - products_infos = src.product.get_products_infos(products, cfg) - - products_infos = [pi for pi in products_infos if not( - src.product.product_is_native(pi[1]) or - src.product.product_is_fixed(pi[1]))] - - return products_infos def log_step(logger, header, step): logger.write("\r%s%s" % (header, " " * 20), 3) @@ -192,7 +157,7 @@ def run(args, runner, logger): src.check_config_has_application( runner.cfg ) # Get the list of products to treat - products_infos = get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Print some informations logger.write(_('Executing the script in the build ' diff --git a/commands/source.py b/commands/source.py index f3066c4..ee8de55 100644 --- a/commands/source.py +++ b/commands/source.py @@ -29,9 +29,6 @@ parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('Optional: products from which to get the sources. This option can be' ' passed several time to get the sources of several products.')) -parser.add_option('', 'properties', 'string', 'properties', - _('Optional: Filter the products by their properties.\n\tSyntax: ' - '--properties :')) def get_source_for_dev(config, product_info, source_dir, logger, pad): '''The method called if the product is in development mode @@ -531,16 +528,6 @@ def run(args, runner, logger): # check that the command has been called with an application src.check_config_has_application( runner.cfg ) - # Verify the --properties option - if options.properties: - oExpr = re.compile(prepare.PROPERTY_EXPRESSION) - if not oExpr.search(options.properties): - msg = _('WARNING: the "--properties" options must have the ' - 'following syntax:\n--properties :') - logger.write(src.printcolors.printcWarning(msg), 1) - logger.write("\n", 1) - options.properties = None - # Print some informations logger.write(_('Getting sources of the application %s\n') % src.printcolors.printcLabel(runner.cfg.VARS.application), 1) @@ -549,7 +536,7 @@ def run(args, runner, logger): logger.write("\n", 2, False) # Get the products list with products informations regarding the options - products_infos = prepare.get_products_list(options, runner.cfg, logger) + products_infos = src.product.get_products_list(options, runner.cfg, logger) # Call to the function that gets all the sources good_result, results = get_all_product_sources(runner.cfg, diff --git a/src/options.py b/src/options.py index 911cb71..af890e9 100755 --- a/src/options.py +++ b/src/options.py @@ -23,6 +23,7 @@ parameters in salomeTools command lines import getopt import sys +import re import pprint as PP from . import printcolors @@ -85,9 +86,10 @@ class Options(object): """ # The options field stocks all options of a command # in a list that contains dicts + self.PROPERTY_EXPRESSION = "^.+:.+$" self.options = [] # The list of available option type - self.availableOptions = "noboolean boolean string int float long list list2 level".split() + self.availableOptions = "noboolean boolean string int float long list list2 level properties".split() self.noArgOptions = "noboolean boolean".split() self.default = None self.results = {} @@ -127,6 +129,14 @@ class Options(object): option['result'] = default self.options.append(option) + + # add option properties unconditionaly if 'products' option added + if [shortName, longName] == ["p", "products"]: + self.add_option('', 'properties', 'properties', 'properties', + _('Optional: Filter the products by their properties.\n\tSyntax: ' + '--properties :')) + + def getDetailOption(self, option): """ @@ -241,6 +251,8 @@ class Options(object): if option['result'] is None: option['result'] = list() option['result'] = self.filterList2(opt[1]) + elif optionType == "properties": + option['result'] = self.filterProperties(opt[1]) optResult.__setattr__(option['destName'], option['result']) # free the option in order to be able to make @@ -248,7 +260,7 @@ class Options(object): option['result'] = None self.results = {"optlist": optlist, "optResult": optResult, "args": args, "argList": argList} - DBG.write("results", self.results) + DBG.write("results", self.results, True) return optResult, args def filterLevel(self, aLevel): @@ -272,30 +284,45 @@ class Options(object): aList = [i for i in aList if i != ""] # split old list leadin "," as ",KERNEL,ETC..." return aList + def filterProperties(self, aStr): + """ + filter properties values + + example: + >> sat -v 9 prepare $TRG -p KERNEL --properties is_SALOME_module:yes + """ + msg = _('The "--properties" option must have the following syntax:\n--properties :') + oExpr = re.compile(self.PROPERTY_EXPRESSION) + if not oExpr.search(aStr): + raise Exception(msg) + res = aStr.split(":") + if len(res) != 2: + raise Exception(msg) + return res def __repr__(self): - """ - repr for only self.options and self.results (if present) - """ - aDict = {'options': self.options, 'results': self.results} - aStr = PP.pformat(aDict) - res = "%s(\n %s\n)" % (self.__class__.__name__, aStr[1:-1]) - return res + """ + repr for only self.options and self.results (if present) + """ + aDict = {'options': self.options, 'results': self.results} + aStr = PP.pformat(aDict) + res = "%s(\n %s\n)" % (self.__class__.__name__, aStr[1:-1]) + return res def __str__(self): - """ - str for only resume expected self.options - """ - #aDict = [(k["longName"], k["shortName", k["helpString"]) for k in self.options} - #aList = [(k, self.options[k]) for k in sorted(self.options.keys())] - aDict = {} - for o in self.options: - aDict[o["longName"]] = (o["shortName"], o["helpString"]) - aStr = PP.pformat(aDict) - res = "%s(\n %s)" % (self.__class__.__name__, aStr[1:-1]) - return res + """ + str for only resume expected self.options + """ + #aDict = [(k["longName"], k["shortName", k["helpString"]) for k in self.options} + #aList = [(k, self.options[k]) for k in sorted(self.options.keys())] + aDict = {} + for o in self.options: + aDict[o["longName"]] = (o["shortName"], o["helpString"]) + aStr = PP.pformat(aDict) + res = "%s(\n %s)" % (self.__class__.__name__, aStr[1:-1]) + return res def debug_write(self): - DBG.write("options and results", self, True) + DBG.write("options and results", self, True) diff --git a/src/product.py b/src/product.py index 0c6fe4b..45cfef8 100644 --- a/src/product.py +++ b/src/product.py @@ -23,6 +23,7 @@ relative to the product notion of salomeTools import os import re +import pprint as PP import src import src.debug as DBG @@ -507,11 +508,89 @@ def get_products_infos(lproducts, config): if prod_info is not None: products_infos.append((prod, prod_info)) else: - msg = _("The %s product has no definition " - "in the configuration.") % prod + msg = _("The %s product has no definition in the configuration.") % prod raise src.SatException(msg) return products_infos + +def get_products_list(options, cfg, logger): + """ + method that gives the product list with their informations from + configuration regarding the passed options. + + :param options Options: The Options instance that stores the commands arguments + :param cfg Config: The global configuration + :param logger Logger: The logger instance to use for the display and logging + :return: The list of (product name, product_informations). + :rtype: List + """ + # Get the products to be prepared, regarding the options + if options.products is None: + # No options, get all products sources + products = cfg.APPLICATION.products + else: + # if option --products, check that all products of the command line + # are present in the application. + 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} ) + + # Construct the list of tuple containing + # the products name and their definition + resAll = src.product.get_products_infos(products, cfg) + + # if the property option was passed, filter the list + if options.properties: # existing properties + ok = [] + ko = [] + res =[] + prop, value = options.properties # for example 'is_SALOME_module', 'yes' + for p_name, p_info in resAll: + try: + if p_info.properties[prop] == value: + res.append((p_name, p_info)) + ok.append(p_name) + else: + ko.append(p_name) + except: + ok.append(p_name) + + if len(ok) != len(resAll): + logger.trace("on properties %s\n products accepted:\n %s\n products rejected:\n %s\n" % + (options.properties, PP.pformat(sorted(ok)), PP.pformat(sorted(ko)))) + else: + logger.warning("properties %s\n seems useless with no products rejected" % + (options.properties)) + else: + res = resAll # not existing properties as all accepted + + + ok = [] + ko = [] + products_infos = [] + for p_name, p_info in res: + try: + if src.product.product_is_native(p_info) or src.product.product_is_fixed(p_info): + ko.append(p_name) + else: + products_infos.append((p_name, p_info)) + ok.append(p_name) + except: + msg = "problem on 'is_native' or 'is_fixed' for product %s" % p_name + raise Exception(msg) + + if len(ko) > 0: + logger.warning("on is_native or is_fixed\n products accepted:\n %s\n products rejected:\n %s\n" % + (PP.pformat(sorted(ok)), PP.pformat(sorted(ko)))) + + logger.debug("products selected:\n %s\n" % PP.pformat(sorted(ok))) + + return res + + def get_product_dependencies(config, product_info): """\ Get recursively the list of products that are -- 2.39.2