From 3da634c398d449ffc6c2a9e55c4641835b889083 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Sat, 26 May 2018 14:27:15 +0200 Subject: [PATCH] fix option -v, TODO config.USER.output_verbose_level < (integer) --- commands/generate.py | 10 ++------- data/local.pyconf | 7 ++----- src/coloringSat.py | 7 +++++-- src/compilation.py | 37 +++++++++++++-------------------- src/loggingSat.py | 29 ++++++++++++++++++++++---- src/options.py | 11 +++++----- src/salomeTools.py | 13 +++++++++--- src/utilsSat.py | 34 +++++++++++++++++++++++++++++- src/xmlManager.py | 49 +------------------------------------------- 9 files changed, 97 insertions(+), 100 deletions(-) diff --git a/commands/generate.py b/commands/generate.py index 21f65e3..04becef 100644 --- a/commands/generate.py +++ b/commands/generate.py @@ -143,14 +143,8 @@ def generate_component_list(config, product_info, context, logger): logger.info("\n") for compo in PROD.get_product_components(product_info): header = " %s %s " % (UTS.label(compo), "." * (20 - len(compo))) - res = generate_component(config, - compo, - product_info, - context, - header, - logger) - if config.USER.output_verbose_level == 3: - logger.info("\r%s%s\r%s" % (header, " " * 20, header)) + res = generate_component(config, compo, product_info, context, header, logger) + logger.info("\r%s%s\r%s" % (header, " " * 20, header)) logger.info(res + "\n") return res diff --git a/data/local.pyconf b/data/local.pyconf index e62c609..c91da53 100644 --- a/data/local.pyconf +++ b/data/local.pyconf @@ -12,10 +12,7 @@ { project_file_paths : [ - "/volatile/wambeke/SAT5/SAT5_S840_MATIX24/SAT_SALOME/salome.pyconf", - # "/home/uranietm/proJET/saTJOBS/saT5/uranie.pyconf", - # cloned 2017/12 for matix - # "/home/matix/GitRepo/uranie/saT5/uranie.pyconf", - # "/volatile/wambeke/SAT5/SAT_MATIX/matix.pyconf" + "/home/christian/SAT_SALOME/salome.pyconf" + "/home/christian/SAT_MATIX/matix.pyconf" ] } diff --git a/src/coloringSat.py b/src/coloringSat.py index 046b9bc..3bf179d 100755 --- a/src/coloringSat.py +++ b/src/coloringSat.py @@ -105,10 +105,13 @@ _tags = _tags + [ # more non empty colored smart tags reversed order _tagsNone = [ - (FG.GREEN + ST.BRIGHT + "OK" + ST.RESET_ALL, "OK"), - (FG.RED + ST.BRIGHT + "KO" + ST.RESET_ALL, "KO"), + ("", "OK"), + ("", "KO"), ] + _tagsNone +# import pprint as PP +# print("_tags %s" % PP.pformat(_tags)) +# print("_tagsNone %s" % PP.pformat(_tagsNone)) def indent(msg, nb, car=" "): """indent nb car (spaces) multi lines message except first one""" diff --git a/src/compilation.py b/src/compilation.py index abc06fa..69a635f 100644 --- a/src/compilation.py +++ b/src/compilation.py @@ -73,7 +73,6 @@ class Builder: Prepares the environment. Build two environment: one for building and one for testing (launch). """ - if not self.build_dir.exists(): # create build dir self.build_dir.make() @@ -87,14 +86,12 @@ class Builder: #environ_info.append(self.product_info.name) # create build environment - self.build_environ = ENVI.SalomeEnviron( - self.config, ENVI.Environ(dict(os.environ)), True) + self.build_environ = ENVI.SalomeEnviron(self.config, ENVI.Environ(dict(os.environ)), True) self.build_environ.silent = (self.config.USER.output_verbose_level < 5) self.build_environ.set_full_environ(self.logger, environ_info) # create runtime environment - self.launch_environ = ENVI.SalomeEnviron( - self.config, ENVI.Environ(dict(os.environ)), False) + self.launch_environ = ENVI.SalomeEnviron(self.config, ENVI.Environ(dict(os.environ)), False) self.launch_environ.silent = True # no need to show here self.launch_environ.set_full_environ(self.logger, environ_info) @@ -105,10 +102,9 @@ class Builder: return 0 - ## - # Runs cmake with the given options. - def cmake(self, options=""): + def cmake(self, options=""): + """Runs cmake with the given options.""" cmake_option = options # cmake_option +=' -DCMAKE_VERBOSE_MAKEFILE=ON -DSALOME_CMAKE_DEBUG=ON' if 'cmake_options' in self.product_info: @@ -144,10 +140,9 @@ class Builder: else: return 1 - ## - # Runs build_configure with the given options. - def build_configure(self, options=""): + def build_configure(self, options=""): + """Runs build_configure with the given options.""" if 'buildconfigure_options' in self.product_info: options += " %s " % self.product_info.buildconfigure_options @@ -167,10 +162,9 @@ class Builder: else: return 1 - ## - # Runs configure with the given options. - def configure(self, options=""): + def configure(self, options=""): + """Runs configure with the given options.""" if 'configure_options' in self.product_info: options += " %s " % self.product_info.configure_options @@ -244,10 +238,8 @@ CC=\\"hack_libtool\\"%g" libtool''' else: return 1 - ## - # Runs msbuild to build the module. def wmake(self,nb_proc, opt_nb_proc = None): - + """Runs msbuild to build the module.""" hh = 'MSBUILD /m:%s' % str(nb_proc) if self.debug_mode: hh += " " + UTS.red("DEBUG") @@ -274,9 +266,9 @@ CC=\\"hack_libtool\\"%g" libtool''' else: return 1 - ## - # Runs 'make install'. + def install(self): + """Runs 'make install'.""" if self.config.VARS.dist_name=="Win": command = 'msbuild INSTALL.vcxproj' if self.debug_mode: @@ -301,9 +293,9 @@ CC=\\"hack_libtool\\"%g" libtool''' else: return 1 - ## - # Runs 'make_check'. + def check(self, command=""): + """Runs 'make_check'.""" if ARCH.is_windows(): cmd = 'msbuild RUN_TESTS.vcxproj' else : @@ -329,12 +321,11 @@ CC=\\"hack_libtool\\"%g" libtool''' else: return 1 - ## - # Performs a default build for this module. def do_default_build(self, build_conf_options="", configure_options="", show_warning=True): + """Performs a default build for this module.""" use_autotools = False if 'use_autotools' in self.product_info: uc = self.product_info.use_autotools diff --git a/src/loggingSat.py b/src/loggingSat.py index 70670d8..87cab85 100755 --- a/src/loggingSat.py +++ b/src/loggingSat.py @@ -387,7 +387,15 @@ class LoggerSat(LOGI.Logger): self.idCommandHandlers += 1 log("setFileHandler %s" % logger) return self.idCommandHandlers - + + def setLevelMainHandler (self, level): + for handl in list(self.handlers): # get main handler + if handl.idCommandHandlers == 0: + log("setLevelMainHandler %s" % level) + handl.setLevel(level) + return + raise Exception("main handler not found for level %s" % level) + def closeFileHandlerForCommand(self, cmdInstance): for handl in list(self.handlers): # get original list try: # may be foreign handlers without idCommandHandlers attribute @@ -746,7 +754,7 @@ def initLoggerAsDefault(logger, fmt=None, level=None): # import src/debug as DBG # tmp = (logger.getEffectiveLevel(), LOGI.NOTSET, logger.level, logger.parent.level) # DBG.write("logger levels tmp, True) - if level is not None: # level could be modified during execution.... + if level is not None: # level could be modified during execution handler.setLevel(level) # on screen log as user wants else: handler.setLevel(LOGI.INFO) # on screen no log step, which are in xml files @@ -850,8 +858,21 @@ def testMain(): from colorama import Fore as FG from colorama import Style as ST - print("this is unconditionally %scolored in green%s !!!" % (FG.GREEN, ST.RESET_ALL)) - + print("this is unconditionally %scolored in green%s !!!" % (FG.GREEN, ST.RESET_ALL)) + + import src.utilsSat as UTS + import src.coloringSat as COLS + print("\n1234567890123456789012345678901234567890123456789012345678901234567890") + print(UTS.tabColor(10, "0", 10, "1", 10, "2", 10, "3", 10, "4", 10, "5", 10, "6")) + print(UTS.tabColor(20, "1 tabulated", 15, "21 OK here", 10, "36 OK end")) + print(COLS.toColor(UTS.tabColor(20, "1 tabulated", 15, "21 here", 10, "36 end"))) + print('toColor(20, "1 tabulated", 15, "21 here", 10, "36 end")') + + print("\n1234567890123456789012345678901234567890123456789012345678901234567890") + print(UTS.tabColor(10, "0", 10, "1", 10, "2", 10, "3", 10, "4", 10, "5", 10, "6")) + print(UTS.tabColor(-20, "tabulated 20", -15, "OK here 35", -10, "OK end 45")) + print(COLS.toColor(UTS.tabColor(-20, "tabulated 20", -15, " here 35", -10, " end 45"))) + print('toColor(-20, "tabulated 20", -15, " here 35", -10, " end 45")') ################################################################# diff --git a/src/options.py b/src/options.py index 8bb831e..48da2fd 100644 --- a/src/options.py +++ b/src/options.py @@ -35,8 +35,8 @@ class OptResult(object): The aim of this class is to have an elegant syntax to manipulate the options. | Example: - | >> print(options.level) - | >> 5 + | >> print(options.output_verbose_level) + | >> 'INFO' """ def __init__(self): """Initialization @@ -90,8 +90,7 @@ class Options(object): self.default = None self.results = {} - def add_option(self, shortName, longName, - optionType, destName, helpString="", default = None): + def add_option(self, shortName, longName, optionType, destName, helpString="", default=None): """ Add an option to a command. It gets all attributes of an option and append it in the options field @@ -259,9 +258,9 @@ class Options(object): for i in range(maxLen): for lev in knownLevels: if aLev == lev[:i]: - DBG.write("filterLevel", "%s -> %s" % (aLevel, lev), True) + DBG.write("filterLevel", "%s -> %s" % (aLevel, lev)) return lev - msg = "Unknown level '%s', accepted are:\n%s" % (aLev, ",".join(knownLevels)) + msg = "Unknown level '%s', accepted are:\n%s" % (aLev, ", ".join(knownLevels)) raise Exception(msg) def filterList2(self, aStr): diff --git a/src/salomeTools.py b/src/salomeTools.py index bed28dc..46cd314 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -368,6 +368,8 @@ class _BaseCommand(object): if remaindersArgs != []: msg = "%s.Command have unknown remainders arguments:\n(%s)" % (fullName, " ".join(remaindersArgs)) self.getLogger().error(msg) + + self.getLogger().trace("%s.Command options\n%s" % (fullName, commandOptions)) return commandOptions, remaindersArgs def description(self): @@ -494,7 +496,7 @@ class Sat(object): _("overwrites a configuration parameters.")) parser.add_option('v', 'verbose', 'level', "output_verbose_level", - _("change console output verbose level (default is INFO).")) + _("change console output verbose level (default is INFO)."), "INFO") parser.add_option('d', 'devel', 'noboolean', "development mode", _("""\ @@ -515,8 +517,8 @@ development mode (more verbose error/exception messages) def parseArguments(self, arguments): args = self.assumeAsList(arguments) genericOptions, remaindersArgs = self.parser.parse_args(args) - DBG.write("Sat generic options", genericOptions, True) - DBG.write("Sat remainders arguments", remaindersArgs, True) + DBG.write("Sat generic options", genericOptions) + DBG.write("Sat remainders arguments", remaindersArgs) return genericOptions, remaindersArgs @@ -572,6 +574,11 @@ development mode (more verbose error/exception messages) return RCO.ReturnCode("OK", "No arguments, as 'sat --help'") self.options, remainderArgs = self.parseArguments(args) + # set main handler level + logger = self.getLogger() + logger.setLevelMainHandler(self.options.output_verbose_level) + + logger.trace("generic options\n%s" % self.options) # if the help option has been called, print command help and returns if self.options.help: diff --git a/src/utilsSat.py b/src/utilsSat.py index f8ecd2d..158367f 100644 --- a/src/utilsSat.py +++ b/src/utilsSat.py @@ -500,7 +500,39 @@ def error(msg): def critical(msg): return ""+msg+"" - + +def tabColor(*args): + """ + return tabulated colored string from args, + assume true length of color tags as etc. to correct alignment + when tags are interpreted as (no-length-spacing) color + for colorama use or else + """ + # DBG.write("tabulate args %s" % type(args), args, True) + i = 0 + imax = len(args) + res = "" + for ii in range(30): # no more 30 items + idx, aStr = args[i:i+2] + if idx > 0: + res += aStr + addSpaces(idx, aStr) # left aligment + else: + res += addSpaces(idx, aStr) + aStr # right aligment + i += 2 + if i >= imax: + return res + # something wrong + #Raise Exception("tabColor problem on %s" % args) + +def addSpaces(idx, aStr): + import src.coloringSat as COLS + cleaned = COLS.cleanColors(aStr) + # DBG.write("cleaned", "'%s' ->\n'%s'" % (aStr, cleaned), True) + lg = abs(idx) - len(cleaned) + if lg <= 0: + return "" + else: + return " "*lg ############################################################################## # list and dict utilities diff --git a/src/xmlManager.py b/src/xmlManager.py index 5a51d07..be233bb 100644 --- a/src/xmlManager.py +++ b/src/xmlManager.py @@ -261,54 +261,7 @@ class XmlLogFile(object): with open(self.pyconfFile, 'w') as f: config.__save__(f) - - def write(self, message, level=None, screenOnly=False): - """ - function used in the commands - to print in the terminal and the log file. - - :param message: (str) The message to print. - :param level: (int) - The output level corresponding to the message 0 < level < 6. - :param screenOnly: (bool) if True, do not write in log file. - """ - # do not write message starting with \r to log file - if not message.startswith("\r") and not screenOnly: - self.xmlFile.append_node_text("Log", - printcolors.cleancolor(message)) - - # get user or option 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 - message = printcolors.cleancolor(message) - - # Print message regarding the output level value - if level: - if level <= current_output_verbose_level and not self.silentSysStd: - sys.stdout.write(message) - else: - if self.default_level <= current_output_verbose_level and not self.silentSysStd: - sys.stdout.write(message) - self.flush() - - def error(self, message): - """Print an error. - - :param message: (str:) The message to print. - """ - # Print in the log file - self.xmlFile.append_node_text("traces", _('ERROR:') + message) - - # Print in the terminal and clean colors if the terminal - # is redirected by user - if not ('isatty' in dir(sys.stderr) and sys.stderr.isatty()): - sys.stderr.write(printcolors.printcError(_('ERROR:') + message)) - else: - sys.stderr.write(_('ERROR:') + message) - - + ############################################################################## class ReadXmlFile(object): -- 2.39.2