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
{
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"
]
}
# 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>", "OK"),
+ ("<KO>", "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"""
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()
#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)
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:
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
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
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")
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:
else:
return 1
- ##
- # Runs 'make_check'.
+
def check(self, command=""):
+ """Runs 'make_check'."""
if ARCH.is_windows():
cmd = 'msbuild RUN_TESTS.vcxproj'
else :
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
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
# 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
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 <green>tabulated<reset>", 15, "21 <OK> <info>here<reset>", 10, "36 <OK> end")))
+ print('toColor(20, "1 <green>tabulated<reset>", 15, "21 <OK> <info>here<reset>", 10, "36 <OK> 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, "<green>tabulated<reset> 20", -15, "<OK> <info>here<reset> 35", -10, "<OK> end 45")))
+ print('toColor(-20, "<green>tabulated<reset> 20", -15, "<OK> <info>here<reset> 35", -10, "<OK> end 45")')
#################################################################
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
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
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):
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):
_("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",
_("""\
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
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:
def critical(msg):
return "<critical>"+msg+"<reset>"
-
+
+def tabColor(*args):
+ """
+ return tabulated colored string from args,
+ assume true length of color tags as <OK> <info> 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
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):