X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=commands%2Fpatch.py;h=30b7332d69a5a89b76ba28b81813da367eea28b6;hb=1e5fa46fe1c6130d83712fd8bb959a1f2bf47cbf;hp=589d9ccc0ad04c3b1a4d86374b7723f08cdbe945;hpb=3014b77ba9105e6f638852c48eea7cb3a25248a8;p=tools%2Fsat.git diff --git a/commands/patch.py b/commands/patch.py index 589d9cc..30b7332 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -20,54 +20,69 @@ import os import subprocess import src +import prepare -# Define all possible option for log command : sat log +# Define all possible option for patch command : sat patch parser = src.options.Options() -parser.add_option('m', 'module', 'list2', 'modules', - _('modules to get the sources. This option can be' - ' passed several time to get the sources of several modules.')) -parser.add_option('', 'no_sample', 'boolean', 'no_sample', - _("do not get sources from sample modules.")) +parser.add_option('p', 'products', 'list2', 'products', + _('products to get the sources. This option can be' + ' passed several time to get the sources of several products.')) -def apply_patch(config, module_info, logger): - '''The method called to apply patches on a module +def apply_patch(config, product_info, max_product_name_len, logger): + '''The method called to apply patches on a product :param config Config: The global configuration - :param module_info Config: The configuration specific to - the module to be prepared + :param product_info Config: The configuration specific to + the product to be patched :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) - logger.write("\n", 1) + + if not "patches" in product_info or len(product_info.patches) == 0: + # display and log + logger.write('%s: ' % src.printcolors.printcLabel(product_info.name), 4) + logger.write(' ' * (max_product_name_len - len(product_info.name)), 4, False) + logger.write("\n", 4, False) + msg = _("No patch for the %s product") % product_info.name + logger.write(msg, 4) + logger.write("\n", 4) return True, "" + else: + # display and log + logger.write('%s: ' % src.printcolors.printcLabel(product_info.name), 3) + logger.write(' ' * (max_product_name_len - len(product_info.name)), 3, False) + logger.write("\n", 4, False) - if not os.path.exists(module_info.source_dir): - msg = _("No sources found for the %s module\n") % module_info.name + if not os.path.exists(product_info.source_dir): + msg = _("No sources found for the %s product\n") % product_info.name 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: + # Loop on all the patches of the product + for patch in product_info.patches: details = [] # 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 = "patch" # old patch command (now replace by patching.py) patch_exe = os.path.join(config.VARS.srcDir, "patching.py") patch_cmd = "python %s -p1 -- < %s" % (patch_exe, patch) + # Write the command in the terminal if verbose level is at 5 logger.write((" >%s\n" % patch_cmd),5) + + # Write the command in the log file (can be seen using 'sat log') + logger.logTxtFile.write("\n >%s\n" % patch_cmd) + logger.logTxtFile.flush() + + # Call the command res_cmd = (subprocess.call(patch_cmd, shell=True, - cwd=module_info.source_dir, + cwd=product_info.source_dir, stdout=logger.logTxtFile, stderr=subprocess.STDOUT) == 0) else: @@ -84,10 +99,10 @@ def apply_patch(config, module_info, logger): message = src.printcolors.printcWarning( _("Failed to apply patch %s") % patch) - if config.USER.output_level >= 3: + if config.USER.output_verbose_level >= 3: retcode.append(" %s" % message) else: - retcode.append("%s: %s" % (module_info.name, message)) + retcode.append("%s: %s" % (product_info.name, message)) if len(details) > 0: retcode.extend(details) @@ -103,7 +118,7 @@ def description(): :rtype: str ''' return _("The patch command apply the patches on the sources of " - "the application modules if there is any") + "the application products if there is any") def run(args, runner, logger): '''method that is called when salomeTools is called with patch parameter. @@ -118,47 +133,23 @@ def run(args, runner, logger): logger.write('Patching 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) + src.printcolors.print_value(logger, 'workdir', + runner.cfg.APPLICATION.workdir, 2) logger.write("\n", 2, False) - # Get the modules to be prepared, regarding the options - if options.modules is None: - # No options, get all modules sources - modules = runner.cfg.APPLICATION.modules - else: - # if option --modules, check that all modules of the command line - # are present in the application. - modules = options.modules - for m in modules: - if m not in runner.cfg.APPLICATION.modules: - raise src.SatException(_("Module %(module)s " - "not defined in application %(application)s") % - { 'module': m, 'application': runner.cfg.VARS.application} ) - - # Construct the list of tuple containing - # the modules name and their definition - modules_infos = src.module.get_modules_infos(modules, runner.cfg) - - # 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) + # Get the products list with products informations regarding the options + products_infos = prepare.get_products_list(options, runner.cfg, logger) # Get the maximum name length in order to format the terminal display - max_module_name_len = 1 - if len(modules_infos) > 0: - max_module_name_len = max(map(lambda l: len(l), modules_infos[0])) + 4 + max_product_name_len = 1 + if len(products_infos) > 0: + max_product_name_len = max(map(lambda l: len(l), products_infos[0])) + 4 - # The loop on all the modules on which to apply the patches + # The loop on all the products on which to apply the patches good_result = 0 - for module_name, module_info in modules_infos: - # display and log - logger.write('%s: ' % src.printcolors.printcLabel(module_name), 3) - logger.write(' ' * (max_module_name_len - len(module_name)), 3, False) - logger.write("\n", 4, False) - return_code, patch_res = apply_patch(runner.cfg, module_info, logger) + for __, product_info in products_infos: + # Apply the patch + return_code, patch_res = apply_patch(runner.cfg, product_info, max_product_name_len, logger) logger.write(patch_res, 1, False) if return_code: good_result += 1 @@ -166,16 +157,16 @@ def run(args, runner, logger): # Display the results (how much passed, how much failed, etc...) logger.write("\n", 2, False) - if good_result == len(modules_infos): + if good_result == len(products_infos): status = src.OK_STATUS res_count = "%d / %d" % (good_result, good_result) else: status = src.KO_STATUS - res_count = "%d / %d" % (good_result, len(modules)) + res_count = "%d / %d" % (good_result, len(products_infos)) # write results logger.write("Patching sources of the application:", 1) logger.write(" " + src.printcolors.printc(status), 1, False) logger.write(" (%s)\n" % res_count, 1, False) - return len(modules_infos) - good_result \ No newline at end of file + return len(products_infos) - good_result \ No newline at end of file