From d525421ab1fc657057b2b1da0711be79efad7ef1 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Mon, 18 Apr 2016 14:24:46 +0200 Subject: [PATCH] rename level into verbose, and set verbose 0 to silent option --- commands/config.py | 4 ++-- commands/patch.py | 11 ++++++++--- salomeTools.py | 19 +++++++++---------- src/logger.py | 6 +++--- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/commands/config.py b/commands/config.py index f12e724..9d35e54 100644 --- a/commands/config.py +++ b/commands/config.py @@ -356,8 +356,8 @@ class ConfigManager: "This is the user name used to access salome cvs base.\n") user_cfg.USER.addMapping('svn_user', config.VARS.user, "This is the user name used to access salome svn base.\n") - user_cfg.USER.addMapping('output_level', 3, - "This is the default output_level you want." + user_cfg.USER.addMapping('output_verbose_level', 3, + "This is the default output_verbose_level you want." " 0=>no output, 5=>debug.\n") user_cfg.USER.addMapping('publish_dir', os.path.join(os.path.expanduser('~'), diff --git a/commands/patch.py b/commands/patch.py index 90ae305..e118708 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -61,14 +61,18 @@ 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 = "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=product_info.source_dir, @@ -88,7 +92,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)) @@ -126,7 +130,7 @@ def run(args, runner, logger): runner.cfg.APPLICATION.out_dir, 2) logger.write("\n", 2, False) - # Get the products list with products informations reagrding the options + # 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 @@ -141,6 +145,7 @@ def run(args, runner, logger): 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) + # Apply the patch return_code, patch_res = apply_patch(runner.cfg, product_info, logger) logger.write(patch_res, 1, False) if return_code: diff --git a/salomeTools.py b/salomeTools.py index 3f43128..09267ba 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -75,10 +75,8 @@ parser.add_option('o', 'overwrite', 'list', "overwrite", _("overwrites a configuration parameters.")) parser.add_option('g', 'debug', 'boolean', 'debug_mode', _("run salomeTools in debug mode.")) -parser.add_option('l', 'level', 'int', "output_level", - _("change output level (default is 3).")) -parser.add_option('s', 'silent', 'boolean', 'silent', - _("do not write log or show errors.")) +parser.add_option('v', 'verbose', 'int', "output_verbose_level", + _("change output verbose level (default is 3).")) class Sat(object): '''The main class that stores all the commands of salomeTools @@ -167,15 +165,16 @@ class Sat(object): command=__nameCmd__) # set output level - if self.options.output_level: - self.cfg.USER.output_level = self.options.output_level - if self.cfg.USER.output_level < 1: - self.cfg.USER.output_level = 1 - + if self.options.output_verbose_level is not None: + self.cfg.USER.output_verbose_level = self.options.output_verbose_level + if self.cfg.USER.output_verbose_level < 1: + self.cfg.USER.output_verbose_level = 0 + silent = (self.cfg.USER.output_verbose_level == 0) + # create log file, unless the command is called # with a logger as parameter logger_command = src.logger.Logger(self.cfg, - silent_sysstd=self.options.silent) + silent_sysstd=silent) if logger: logger_command = logger diff --git a/src/logger.py b/src/logger.py index ee0ef40..eddcd55 100644 --- a/src/logger.py +++ b/src/logger.py @@ -114,7 +114,7 @@ class Logger(object): printcolors.cleancolor(message)) # get user or option output level - current_output_level = self.config.USER.output_level + current_output_verbose_level = self.config.USER.output_verbose_level if not ('isatty' in dir(sys.stdout) and sys.stdout.isatty()): # clean the message color if the terminal is redirected by user # ex: sat compile appli > log.txt @@ -122,10 +122,10 @@ class Logger(object): # Print message regarding the output level value if level: - if level <= current_output_level and not self.silentSysStd: + if level <= current_output_verbose_level and not self.silentSysStd: sys.stdout.write(message) else: - if self.default_level <= current_output_level and not self.silentSysStd: + if self.default_level <= current_output_verbose_level and not self.silentSysStd: sys.stdout.write(message) def error(self, message): -- 2.39.2