From: Serge Rehbinder Date: Wed, 9 Mar 2016 09:25:51 +0000 (+0100) Subject: Add prepare command X-Git-Tag: sprint-03~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3014b77ba9105e6f638852c48eea7cb3a25248a8;p=tools%2Fsat.git Add prepare command --- diff --git a/commands/patch.py b/commands/patch.py index a1eae4d..589d9cc 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -30,6 +30,16 @@ parser.add_option('', 'no_sample', 'boolean', 'no_sample', _("do not get sources from sample modules.")) def apply_patch(config, module_info, logger): + '''The method called to apply patches on a module + + :param config Config: The global configuration + :param module_info Config: The configuration specific to + the module to be prepared + :param logger Logger: The logger instance to use for the display and logging + :return: (True if it succeed, else False, message to display) + :rtype: (boolean, str) + ''' + if not "patches" in module_info or len(module_info.patches) == 0: msg = _("No patch for the %s module") % module_info.name logger.write(msg, 3) @@ -41,12 +51,15 @@ def apply_patch(config, module_info, logger): logger.write(src.printcolors.printcWarning(msg), 1) return False, "" + # At this point, there one or more patches and the source directory exists retcode = [] res = [] + # Loop on all the patches of the module for patch in module_info.patches: details = [] - - if os.path.isfile(patch) and patch.endswith(".patch"): + + # Check the existence and apply the patch + if os.path.isfile(patch): #patch_exe = "patch" # old patch command (now replace by patch.py) patch_exe = os.path.join(config.VARS.srcDir, "patching.py") patch_cmd = "python %s -p1 -- < %s" % (patch_exe, patch) @@ -120,7 +133,7 @@ def run(args, runner, logger): for m in modules: if m not in runner.cfg.APPLICATION.modules: raise src.SatException(_("Module %(module)s " - "not defined in appplication %(application)s") % + "not defined in application %(application)s") % { 'module': m, 'application': runner.cfg.VARS.application} ) # Construct the list of tuple containing diff --git a/commands/prepare.py b/commands/prepare.py new file mode 100644 index 0000000..4db0527 --- /dev/null +++ b/commands/prepare.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- +# Copyright (C) 2010-2012 CEA/DEN +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import src + +# Define all possible option for log command : sat log +parser = src.options.Options() +parser.add_option('m', 'module', 'list2', 'modules', + _('modules to prepare. This option can be' + ' passed several time to prepare several modules.')) +parser.add_option('', 'no_sample', 'boolean', 'no_sample', + _("do not prepare sample modules.")) +parser.add_option('f', 'force', 'boolean', 'force', + _("force to prepare the modules in development mode.")) + +def description(): + '''method that is called when salomeTools is called with --help option. + + :return: The text to display for the prepare command description. + :rtype: str + ''' + return _("The prepare command apply the patches on the sources of " + "the application modules if there is any") + +def run(args, runner, logger): + '''method that is called when salomeTools is called with prepare parameter. + ''' + + # Parse the options + (options, args) = parser.parse_args(args) + + # check that the command has been called with an application + src.check_config_has_application( runner.cfg ) + + # Construct the option to pass to the source command + args_source = runner.cfg.VARS.application + ' ' + + if options.modules: + args_source += '--module ' + ','.join(options.modules) + + if options.no_sample: + args_source += ' --no_sample' + + if options.force: + args_source += ' --force' + + # Call the source command that gets the source + msg = src.printcolors.printcHeader( + _('Get the sources of the desired modules\n')) + logger.write(msg) + res_source = runner.source(args_source) + + # Construct the option to pass to the patch command + args_patch = args_source.replace(' --force', '') + + # Call the source command that gets the source + msg = src.printcolors.printcHeader( + _('\nApply the patches to the sources of the modules\n')) + logger.write(msg) + res_patch = runner.patch(args_patch) + + return res_source + res_patch \ No newline at end of file diff --git a/commands/source.py b/commands/source.py index a3b68ec..18feada 100644 --- a/commands/source.py +++ b/commands/source.py @@ -31,7 +31,7 @@ parser.add_option('', 'no_sample', 'boolean', 'no_sample', parser.add_option('f', 'force', 'boolean', 'force', _("force to get the sources of the modules in development mode.")) -def prepare_for_dev(config, module_info, source_dir, force, logger, pad): +def get_sources_for_dev(config, module_info, source_dir, force, logger, pad): '''The method called if the module is in development mode :param config Config: The global configuration @@ -299,7 +299,12 @@ def get_module_sources(config, :rtype: boolean ''' if not checkout and is_dev: - return prepare_for_dev(config, module_info, source_dir, force, logger, pad) + return get_sources_for_dev(config, + module_info, + source_dir, + force, + logger, + pad) if module_info.get_method == "git": return get_sources_from_git(module_info, source_dir, logger, pad, @@ -435,7 +440,7 @@ def run(args, runner, logger): src.check_config_has_application( runner.cfg ) # Print some informations - logger.write(_('Preparing sources of the application %s\n') % + logger.write(_('Getting sources of the application %s\n') % src.printcolors.printcLabel(runner.cfg.VARS.application), 1) src.printcolors.print_value(logger, 'out_dir', runner.cfg.APPLICATION.out_dir, 2) @@ -459,7 +464,7 @@ def run(args, runner, logger): for m in modules: if m not in runner.cfg.APPLICATION.modules: raise src.SatException(_("Module %(module)s " - "not defined in appplication %(application)s") % + "not defined in application %(application)s") % { 'module': m, 'application': runner.cfg.VARS.application} ) # Construct the list of tuple containing @@ -469,9 +474,20 @@ def run(args, runner, logger): # if the --no_sample option is invoked, suppress the sample modules from # the list if options.no_sample: - modules_infos = filter(lambda l: not src.module.module_is_sample(l[1]), - modules_infos) - + + lmodules_sample = [m for m in modules_infos if src.module.module_is_sample(m[1])] + + modules_infos = [m for m in modules_infos if m not in lmodules_sample] + + if len(lmodules_sample) > 0: + logger.write(src.printcolors.printcWarning(_("Ignoring the following sample modules:\n")), 1) + for i, module in enumerate(lmodules_sample): + end_text = ', ' + if i+1 == len(lmodules_sample): + end_text = '\n' + + logger.write(module[0] + end_text, 1) + # Call to the function that gets all the sources good_result, results = get_all_module_sources(runner.cfg, modules_infos, @@ -483,7 +499,7 @@ def run(args, runner, logger): details = [] logger.write("\n", 2, False) - if good_result == len(modules): + if good_result == len(modules_infos): res_count = "%d / %d" % (good_result, good_result) else: status = src.KO_STATUS @@ -493,7 +509,7 @@ def run(args, runner, logger): if results[module] == 0 or results[module] is None: details.append(module) - result = len(modules) - good_result + result = len(modules_infos) - good_result # write results logger.write(_("Getting sources of the application:"), 1) diff --git a/salomeTools.py b/salomeTools.py index 41d109c..2ce0d73 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -146,6 +146,7 @@ class Sat(object): :param args str: The directory path containing the commands ''' argv = args.split(" ") + while "" in argv: argv.remove("") # if it is provided by the command line, get the application appliToLoad = None