X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=commands%2Fpatch.py;h=ec438655fd61df9be55ada8452628d251ee8fc97;hb=af61677a8482b671f9a3bb307263a7049b1940f6;hp=fb97f0c399f5de81b1924f68bce9ba67dd8f021e;hpb=713d5abd2d3bb247d0175df72ada29cfaa3129de;p=tools%2Fsat.git diff --git a/commands/patch.py b/commands/patch.py index fb97f0c..ec43865 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -18,19 +18,17 @@ import os import subprocess +import re 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('p', 'product', 'list2', 'products', - _('products to get the sources. This option can be' - ' passed several time to get the sources of several products.')) -parser.add_option('', 'no_sample', 'boolean', 'no_sample', - _("do not get sources from sample products.")) +parser.add_option('p', 'products', 'list2', 'products', + _('Optional: products to get the sources. This option accepts a comma separated list.')) -def apply_patch(config, product_info, logger): +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 @@ -40,12 +38,33 @@ def apply_patch(config, product_info, logger): :return: (True if it succeed, else False, message to display) :rtype: (boolean, str) ''' - + + # if the product is native, do not apply patch + if src.product.product_is_native(product_info): + # 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 = _("The %s product is native. Do not apply " + "any patch.") % product_info.name + logger.write(msg, 4) + logger.write("\n", 4) + return True, "" + 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, 3) - logger.write("\n", 1) + 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(product_info.source_dir): msg = _("No sources found for the %s product\n") % product_info.name @@ -61,11 +80,16 @@ def apply_patch(config, product_info, logger): # 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) - + patch_cmd = "patch -p1 < %s" % 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=product_info.source_dir, @@ -85,7 +109,7 @@ def apply_patch(config, product_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" % (product_info.name, message)) @@ -104,7 +128,8 @@ def description(): :rtype: str ''' return _("The patch command apply the patches on the sources of " - "the application products if there is any") + "the application products if there is any.\n\nexample:\nsat " + "patch SALOME-master --products qt,boost") def run(args, runner, logger): '''method that is called when salomeTools is called with patch parameter. @@ -119,12 +144,12 @@ 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 products list with products informations reagrding the options - products_infos = prepare.get_products_list(options, runner.cfg, logger) + # Get the products list with products informations regarding the options + 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 @@ -133,12 +158,12 @@ def run(args, runner, logger): # The loop on all the products on which to apply the patches good_result = 0 - for product_name, product_info in products_infos: - # display and log - logger.write('%s: ' % src.printcolors.printcLabel(product_name), 3) - logger.write(' ' * (max_product_name_len - len(product_name)), 3, False) - logger.write("\n", 4, False) - return_code, patch_res = apply_patch(runner.cfg, product_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 @@ -158,4 +183,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