From d1b685f724e05b1b6cfae0e3cfef418ebe656a40 Mon Sep 17 00:00:00 2001 From: crouzet Date: Fri, 18 May 2018 10:31:47 +0200 Subject: [PATCH] sat #8596 : add --properties option to compile, prepare, patch and source commands --- commands/compile.py | 28 +++++++++++++++++++++++++++- commands/patch.py | 16 +++++++++++++++- commands/prepare.py | 24 ++++++++++++++++++++++++ commands/source.py | 14 ++++++++++++++ complete_sat.sh | 8 ++++---- 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/commands/compile.py b/commands/compile.py index 9b51a87..4154005 100644 --- a/commands/compile.py +++ b/commands/compile.py @@ -17,7 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os - +import re import src import src.debug as DBG @@ -28,11 +28,16 @@ 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) @@ -87,7 +92,18 @@ def get_products_list(options, cfg, logger): # 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]))] @@ -681,6 +697,16 @@ 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 ' diff --git a/commands/patch.py b/commands/patch.py index f9e88e5..974c28a 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -18,6 +18,7 @@ import os import subprocess +import re import src import prepare @@ -27,6 +28,9 @@ 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 @@ -140,6 +144,16 @@ 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) @@ -183,4 +197,4 @@ def run(args, runner, logger): logger.write(" " + src.printcolors.printc(status), 1, False) logger.write(" (%s)\n" % res_count, 1, False) - return len(products_infos) - good_result \ No newline at end of file + return len(products_infos) - good_result diff --git a/commands/prepare.py b/commands/prepare.py index fc40f64..687d051 100644 --- a/commands/prepare.py +++ b/commands/prepare.py @@ -22,11 +22,16 @@ import os 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', _("Optional: force to prepare the products in development mode.")) parser.add_option('', 'force_patch', 'boolean', 'force_patch', @@ -61,6 +66,15 @@ def get_products_list(options, cfg, logger): # 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 remove_products(arguments, l_products_info, logger): @@ -142,6 +156,16 @@ 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) # Construct the arguments to pass to the clean, source and patch commands diff --git a/commands/source.py b/commands/source.py index c8d34f1..9580ef2 100644 --- a/commands/source.py +++ b/commands/source.py @@ -18,6 +18,7 @@ import os import shutil +import re import src import prepare @@ -28,6 +29,9 @@ 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 @@ -507,6 +511,16 @@ 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) diff --git a/complete_sat.sh b/complete_sat.sh index 6873137..ad1d94b 100755 --- a/complete_sat.sh +++ b/complete_sat.sh @@ -172,17 +172,17 @@ _salomeTools_complete() return 0 ;; source) - opts="--products" + opts="--products --properties" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; patch) - opts="--products" + opts="--products --properties" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; prepare) - opts="--products --force --force_patch" + opts="--products --properties --force --force_patch" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; @@ -207,7 +207,7 @@ _salomeTools_complete() return 0 ;; compile) - opts="--products --with_fathers --with_children --clean_all --clean_make --install_flags --show --stop_first_fail --check --clean_build_after" + opts="--products --properties --with_fathers --with_children --clean_all --clean_make --install_flags --show --stop_first_fail --check --clean_build_after" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; -- 2.39.2