From: Christian Van Wambeke Date: Fri, 27 Apr 2018 17:10:24 +0000 (+0200) Subject: end fix logger.write X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3c652687a537bf6b59c4ffe954b55fa58fdb436d;p=tools%2Fsat.git end fix logger.write --- diff --git a/commands/profile.py b/commands/profile.py index e22b4af..7776f64 100644 --- a/commands/profile.py +++ b/commands/profile.py @@ -214,9 +214,7 @@ def update_pyconf( config, options, logger ): #Save previous version pyconf = config.VARS.product + '.pyconf' pyconfBackup = config.VARS.product + '-backup.pyconf' - logger.write( - _("Updating %(new)s (previous version saved as %(old)s)." ) % \ - { "new": pyconf, "old": pyconfBackup }, 3) + logger.info( _("Updating %s (previous version saved as %s." ) % (pyconf, pyconfBackup) path = config.getPath( pyconf ) shutil.copyfile( os.path.join( path, pyconf ), os.path.join( path, pyconfBackup ) ) diff --git a/doc/_themes/alabaster/alabaster/static/custom.css b/doc/_themes/alabaster/alabaster/static/custom.css deleted file mode 120000 index 5e50e76..0000000 --- a/doc/_themes/alabaster/alabaster/static/custom.css +++ /dev/null @@ -1 +0,0 @@ -../../../../src/custom.css \ No newline at end of file diff --git a/doc/_themes/alabaster/alabaster/static/custom.css b/doc/_themes/alabaster/alabaster/static/custom.css new file mode 100644 index 0000000..a088ba6 --- /dev/null +++ b/doc/_themes/alabaster/alabaster/static/custom.css @@ -0,0 +1,25 @@ +/* This file is for theme alabaster custom. */ + +/* +http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html +set backquotes: ``text`` for code samples more color red +*/ +tt, code { + background-color: #ecf0f3; + color: #842; + /* padding: 1px 2px; */ +} + +/* +set 'Note:' etc size less than titles +*/ +div.admonition p.admonition-title { + font-family: {{ theme_head_font_family }}; + font-weight: normal; + font-size: 16px; + margin: 0 0 10px 0; + padding: 0; + line-height: 1; +} + + diff --git a/doc/src/write_command.rst b/doc/src/write_command.rst index 3d4ff35..a50999d 100644 --- a/doc/src/write_command.rst +++ b/doc/src/write_command.rst @@ -19,7 +19,7 @@ Here are the basic requirements that must be followed in this file in order to a Basic requirements ================== -.. warning :: THIS IS OBSOLETE FOR SAT 5.1 +.. warning:: ALL THIS IS OBSOLETE FOR SAT 5.1 By adding a file *mycommand.py* in the ``commands`` directory, salomeTools will define a new command named ``mycommand``. @@ -91,19 +91,16 @@ The *runner* variable gives also access to other commands of salomeTools: HowTo logger ============== -The logger variable is an instance of the Logger class. -It gives access to the write method. +The logger variable is an instance of the python ``logging`` package class. +It gives access to ``debug, info, warning, error, critical`` methods. -When this method is called, the message passed as parameter +Using these methods, the message passed as parameter will be displayed in the terminal and written in an xml log file. .. code-block:: python - logger.write("My message", 3) # 3 as default + logger.info("My message") -The second argument defines the level of verbosity -that is wanted for this message. -It has to be between 1 and 5 (the most verbose level). HELLO example ============== diff --git a/src/environment.py b/src/environment.py index 66a13de..19a88ab 100644 --- a/src/environment.py +++ b/src/environment.py @@ -305,10 +305,11 @@ class SalomeEnviron: self.python_lib1 = self.get('PYTHON_LIBDIR1') def get_names(self, lProducts): - """Get the products name to add in SALOME_MODULES environment variable - It is the name of the product, except in the case where the is a - component name. And it has to be in SALOME_MODULES variable only - if the product has the property has_salome_hui = "yes" + """\ + Get the products name to add in SALOME_MODULES environment variable + It is the name of the product, except in the case where the is a + component name. And it has to be in SALOME_MODULES variable only + if the product has the property has_salome_hui = "yes" :param lProducts list: List of products to potentially add """ @@ -356,8 +357,9 @@ class SalomeEnviron: self.add_line(1) def set_salome_minimal_product_env(self, product_info, logger): - """Sets the minimal environment for a SALOME product. - xxx_ROOT_DIR and xxx_SRC_DIR + """\ + Sets the minimal environment for a SALOME product. + xxx_ROOT_DIR and xxx_SRC_DIR :param product_info Config: The product description :param logger Logger: The logger instance to display messages @@ -368,11 +370,9 @@ class SalomeEnviron: if 'install_dir' in product_info and product_info.install_dir: self.set(root_dir, product_info.install_dir) elif not self.silent: - logger.write(" " + _("No install_dir for product %s\n") % - product_info.name, 5) + logger.warning(_("No install_dir for product %s\n") % product_info.name) - source_in_package = src.get_property_in_product_cfg(product_info, - "sources_in_package") + source_in_package = src.get_property_in_product_cfg(product_info, "sources_in_package") if not self.for_package or source_in_package == "yes": # set source dir, unless no source dir if not src.product.product_is_fixed(product_info): @@ -381,9 +381,8 @@ class SalomeEnviron: if not self.for_package: self.set(src_dir, product_info.source_dir) else: - self.set(src_dir, os.path.join("out_dir_Path", - "SOURCES", - product_info.name)) + srcDir = os.path.join("out_dir_Path", "SOURCES", product_info.name) + self.set(src_dir, srcDir) def set_salome_generic_product_env(self, pi): """Sets the generic environment for a SALOME product. @@ -513,12 +512,10 @@ class SalomeEnviron: pi = src.product.get_product_config(self.cfg, product) if self.for_package: - pi.install_dir = os.path.join("out_dir_Path", - self.for_package, - pi.name) + pi.install_dir = os.path.join("out_dir_Path", self.for_package, pi.name) if not self.silent: - logger.write(_("Setting environment for %s\n") % product, 4) + logger.info(_("Setting environment for %s\n") % product) self.add_line(1) self.add_comment('setting environ for ' + product) @@ -581,7 +578,8 @@ class SalomeEnviron: def run_env_script(self, product_info, logger=None, native=False): - """Runs an environment script. + """\ + Runs an environment script. :param product_info Config: The product description :param logger Logger: The logger instance to display messages @@ -590,11 +588,10 @@ class SalomeEnviron: env_script = product_info.environ.env_script # Check that the script exists if not os.path.exists(env_script): - raise Exception( - _("Environment script not found: %s") % env_script) + raise Exception(_("Environment script not found: %s") % env_script) if not self.silent and logger is not None: - logger.write(" ** load %s\n" % env_script, 4) + logger.info(" ** load %s\n" % env_script) # import the script and run the set_env function try: @@ -602,14 +599,12 @@ class SalomeEnviron: pyproduct = imp.load_source(product_info.name + "_env_script", env_script) if not native: - pyproduct.set_env(self, - product_info.install_dir, - product_info.version) + pyproduct.set_env(self, product_info.install_dir, product_info.version) else: if "set_nativ_env" in dir(pyproduct): pyproduct.set_nativ_env(self) except: - __, exceptionValue, exceptionTraceback = sys.exc_info() + tmp , exceptionValue, exceptionTraceback = sys.exc_info() print(exceptionValue) import traceback traceback.print_tb(exceptionTraceback) @@ -626,11 +621,10 @@ class SalomeEnviron: return # Check that the script exists if not os.path.exists(script_path): - raise Exception( - _("Environment script not found: %s") % script_path) + raise Exception(_("Environment script not found: %s") % script_path) if not self.silent and logger is not None: - logger.write(" ** load %s\n" % script_path, 4) + logger.info(" ** load %s\n" % script_path) script_basename = os.path.basename(script_path) if script_basename.endswith(".py"): @@ -690,14 +684,14 @@ class FileEnvWriter: """Class to dump the environment to a file. """ def __init__(self, config, logger, out_dir, src_root, env_info=None): - '''Initialization. + """Initialization :param cfg Config: the global config :param logger Logger: The logger instance to display messages :param out_dir str: The directory path where t put the output files :param src_root str: The application working directory :param env_info str: The list of products to add in the files. - ''' + """ self.config = config self.logger = logger self.out_dir = out_dir @@ -715,14 +709,11 @@ class FileEnvWriter: :rtype: str """ if not self.silent: - self.logger.write(_("Create environment file %s\n") % - UTS.label(filename), 3) + self.logger.info(_("Create environment file %s\n") % UTS.label(filename)) # create then env object env_file = open(os.path.join(self.out_dir, filename), "w") - tmp = src.fileEnviron.get_file_environ(env_file, - shell, - {}) + tmp = src.fileEnviron.get_file_environ(env_file, shell, {}) env = SalomeEnviron(self.config, tmp, forBuild, for_package=for_package) env.silent = self.silent @@ -735,11 +726,10 @@ class FileEnvWriter: # The list of products to launch lProductsName = env.get_names(self.config.APPLICATION.products.keys()) - env.set( "SALOME_MODULES", ','.join(lProductsName)) + env.set( "SALOME_MODULES", ','.join(lProductsName)) - # set the products - env.set_products(self.logger, - src_root=self.src_root) + # set the product + env.set_products(self.logger, src_root=self.src_root) # add cleanup and close env.finish(True) @@ -762,8 +752,7 @@ class FileEnvWriter: designed for a package. """ if not self.silent: - self.logger.write(_("Create configuration file %s\n") % - UTS.label(filename.name), 3) + self.logger.info(_("Create configuration file %s\n") % UTS.label(filename.name)) # create then env object tmp = src.fileEnviron.get_file_environ(filename, @@ -774,7 +763,7 @@ class FileEnvWriter: tmp, forBuild=False, for_package=for_package, - enable_simple_env_script = with_commercial) + enable_simple_env_script=with_commercial) env.silent = self.silent if self.env_info is not None: @@ -785,7 +774,7 @@ class FileEnvWriter: # The list of products to launch lProductsName = env.get_names(self.config.APPLICATION.products.keys()) - env.set( "SALOME_MODULES", ','.join(lProductsName)) + env.set( "SALOME_MODULES", ','.join(lProductsName)) # set the products env.set_products(self.logger, @@ -800,14 +789,15 @@ class FileEnvWriter: env.finish(True) class Shell: - """Definition of a Shell. + """\ + Definition of a Shell. """ def __init__(self, name, extension): - '''Initialization. + """Initialization. :param name str: the shell name :param extension str: the shell extension - ''' + """ self.name = name self.extension = extension diff --git a/src/fork.py b/src/fork.py index 5a6582a..d19b9a4 100644 --- a/src/fork.py +++ b/src/fork.py @@ -22,6 +22,7 @@ import time import pickle import subprocess + def show_progress(logger, top, delai, ss=""): """shortcut function to display the progression @@ -30,25 +31,24 @@ def show_progress(logger, top, delai, ss=""): :param delai int: the number max :param ss str: the string to display """ - logger.write("\r%s\r%s %s / %s " % ((" " * 30), ss, top, (delai - top)), 4, - False) - logger.flush() + logger.info("\r%s\r%s %s / %s " % ((" " * 30), ss, top, (delai - top))) + -def write_back(logger, message, level): +def write_back(logger, message): """shortcut function to write at the begin of the line :param logger Logger: The logging instance :param message str: the text to display :param level int: the level of verbosity """ - logger.write("\r%s\r%s" % ((" " * 40), message), level) + logger.info("\r%s\r%s" % ((" " * 40), message)) + -# Launch command -# -------------- def launch_command(cmd, logger, cwd, args=[], log=None): + """Launch command""" if log: log = file(log, "a") - logger.write("launch: %s\n" % cmd, 5, screenOnly=True) + logger.info("launch: %s\n" % cmd) for arg in args: cmd += " " + arg prs = subprocess.Popen(cmd, @@ -59,9 +59,9 @@ def launch_command(cmd, logger, cwd, args=[], log=None): executable='/bin/bash') return prs -# Launch a batch -# -------------- + def batch(cmd, logger, cwd, args=[], log=None, delai=20, sommeil=1): + """Launch a batch""" proc = launch_command(cmd, logger, cwd, args, log) top = 0 sys.stdout.softspace = True @@ -70,7 +70,7 @@ def batch(cmd, logger, cwd, args=[], log=None, delai=20, sommeil=1): if time.time() - begin >= 1: show_progress(logger, top, delai, "batch:") if top == delai: - logger.write("batch: time out KILL\n", 3) + logger.info("batch: time out KILL") import signal os.kill(proc.pid, signal.SIGTERM) break @@ -80,14 +80,14 @@ def batch(cmd, logger, cwd, args=[], log=None, delai=20, sommeil=1): top += 1 sys.stdout.flush() else: - write_back(logger, "batch: exit (%s)\n" % str(proc.returncode), 5) + write_back(logger, "batch: exit (%s)\n" % str(proc.returncode)) return (proc.returncode == 0), top -# Launch a salome process -# ----------------------- + def batch_salome(cmd, logger, cwd, args, getTmpDir, pendant="SALOME_Session_Server", fin="killSalome.py", log=None, delai=20, sommeil=1, delaiapp=0): + """Launch a salome process""" beginTime = time.time() launch_command(cmd, logger, cwd, args, log) @@ -136,7 +136,7 @@ def batch_salome(cmd, logger, cwd, args, getTmpDir, if found: write_back(logger, "batch_salome: started\n", 5) else: - logger.write("batch_salome: FAILED to launch salome or appli\n", 3) + logger.warning("batch_salome: FAILED to launch salome or appli") return False, -1 # salome launched run the script @@ -146,12 +146,12 @@ def batch_salome(cmd, logger, cwd, args, getTmpDir, show_progress(logger, top, delai, "running salome or appli:") if not os.access(os.path.join(tmp_dir, pidictFile), os.F_OK): - write_back(logger, "batch_salome: exit\n", 5) + write_back(logger, "batch_salome: exit") code = True elif top >= delai: # timeout kill the test os.system(fin) - logger.write("batch_salome: time out KILL\n", 3) + logger.info("batch_salome: time out KILL") code = False else: # still waiting diff --git a/src/system.py b/src/system.py index fd59c04..4bb721f 100644 --- a/src/system.py +++ b/src/system.py @@ -157,7 +157,7 @@ def cvs_extract(protocol, user, server, base, tag, product, where, { 'root': server, 'base': base, 'where': str(where.base()), 'tag': opttag, 'product': product, 'command': cmd } - logger.write(command + "\n", 5) + logger.debug(command) if not where.dir().exists(): where.dir().make() @@ -214,7 +214,7 @@ def svn_extract(user, logger.logTxtFile.write(command + "\n") - logger.write(command + "\n", 5) + logger.debug(command) logger.logTxtFile.write("\n" + command + "\n") logger.logTxtFile.flush() res = subprocess.call(command, diff --git a/src/test_module.py b/src/test_module.py index d5a46d4..e2e2ad3 100755 --- a/src/test_module.py +++ b/src/test_module.py @@ -99,8 +99,7 @@ class Test: symlinks=True) def prepare_testbase_from_dir(self, testbase_name, testbase_dir): - self.logger.write(_("get test base from dir: %s\n") % \ - UTS.label(testbase_dir), 3) + self.logger.info(_("get test base from dir: %s\n") % UTS.label(testbase_dir)) if not os.access(testbase_dir, os.X_OK): raise Exception( _("testbase %(name)s (%(dir)s) does not exist ...\n") % \ @@ -113,11 +112,8 @@ class Test: testbase_name, testbase_base, testbase_tag): - self.logger.write( - _("get test base '%(testbase)s' with '%(tag)s' tag from git\n") % \ - { "testbase" : UTS.label(testbase_name), - "tag" : UTS.label(testbase_tag) }, - 3) + self.logger.info( _("get test base '%s' with '%s' tag from git\n") % \ + (UTS.label(testbase_name), UTS.label(testbase_tag)) ) try: def set_signal(): # pragma: no cover """see http://bugs.python.org/issue1652""" @@ -135,7 +131,7 @@ class Test: 'base': testbase_base, 'dir': testbase_name } - self.logger.write("> %s\n" % cmd, 5) + self.logger.debug("> %s" % cmd) if src.architecture.is_windows(): # preexec_fn not supported on windows platform res = subprocess.call(cmd, @@ -161,8 +157,7 @@ class Test: sys.exit(0) def prepare_testbase_from_svn(self, user, testbase_name, testbase_base): - self.logger.write(_("get test base '%s' from svn\n") % - UTS.label(testbase_name), 3) + self.logger.info(_("get test base '%s' from svn\n") % UTS.label(testbase_name)) try: def set_signal(): # pragma: no cover """see http://bugs.python.org/issue1652""" @@ -175,12 +170,12 @@ class Test: 'dir': testbase_name } # Get the application environment - self.logger.write(_("Set the application environment\n"), 5) + self.logger.debug(_("Set the application environment")) env_appli = src.environment.SalomeEnviron(self.config, src.environment.Environ(dict(os.environ))) env_appli.set_application_env(self.logger) - self.logger.write("> %s\n" % cmd, 5) + self.logger.debug("> %s" % cmd) if src.architecture.is_windows(): # preexec_fn not supported on windows platform res = subprocess.call(cmd, @@ -610,7 +605,7 @@ class Test: log=logWay, delaiapp=time_out_salome) - self.logger.write("status = %s, elapsed = %s\n" % (status, elapsed), 5) + self.logger.debug("status = %s, elapsed = %s\n" % (status, elapsed)) # create the test result to add in the config object test_info = PYCONF.Mapping(self.config) @@ -681,9 +676,8 @@ class Test: # Runs all tests of a session. def run_session_tests(self): - self.logger.write(self.write_test_margin(2), 3) - self.logger.write("Session = %s\n" % \ - UTS.label(self.currentsession), 3, False) + self.logger.info(self.write_test_margin(2)) + self.logger.info("Session = %s\n" % UTS.label(self.currentsession)) # prepare list of tests to run tests = os.listdir(os.path.join(self.currentDir, @@ -704,9 +698,8 @@ class Test: ## # Runs all tests of a grid. def run_grid_tests(self): - self.logger.write(self.write_test_margin(1), 3) - self.logger.write("grid = %s\n" % \ - UTS.label(self.currentgrid), 3, False) + self.logger.info(self.write_test_margin(1)) + self.logger.info("grid = %s\n" % UTS.label(self.currentgrid)) grid_path = os.path.join(self.currentDir, self.currentgrid) @@ -723,9 +716,8 @@ class Test: sessions = sorted(sessions, key=str.lower) for session_ in sessions: if not os.path.exists(os.path.join(grid_path, session_)): - self.logger.write(self.write_test_margin(2), 3) - self.logger.write( - UTS.red("Session %s not found" % session_) + "\n", 3, False) + self.logger.info(self.write_test_margin(2)) + self.logger.warning("Session %s not found" % session_)) else: self.currentsession = session_ self.run_session_tests() @@ -744,26 +736,23 @@ class Test: os.environ['TT_BASE_RESSOURCES'] = res_dir logger.debug(" %s = %s\n" % ("TT_BASE_RESSOURCES", res_dir) - self.logger.write("\n", 4, False) - self.logger.write(self.write_test_margin(0), 3) + self.logger.info(self.write_test_margin(0)) testbase_label = "Test base = %s\n" % UTS.label(self.currentTestBase) - self.logger.write(testbase_label, 3, False) - self.logger.write("-" * len(UTS.cleancolor(testbase_label)), 3) - self.logger.write("\n", 3, False) + self.logger.info(testbase_label) + self.logger.info("-" * len(UTS.cleancolor(testbase_label))) # load settings settings_file = os.path.join(res_dir, "test_settings.py") if os.path.exists(settings_file): gdic, ldic = {}, {} execfile(settings_file, gdic, ldic) - self.logger.write(_("Load test settings\n"), 3) + self.logger.info(_("Load test settings")) self.settings = ldic['settings_dic'] self.ignore_tests = ldic['known_failures_list'] if isinstance(self.ignore_tests, list): self.ignore_tests = {} - self.logger.write(UTS.red("known_failur" - "es_list must be a dictionary (not a list)") + "\n", 1, False) + self.logger.error("known failures must be a dictionary (not a list)") else: self.ignore_tests = {} self.settings.clear() @@ -782,18 +771,14 @@ class Test: grids = self.grids # given by user else: # select all the grids (i.e. directories) in the directory - grids = filter(lambda l: l not in C_IGNORE_GRIDS, - os.listdir(self.currentDir)) - grids = filter(lambda l: os.path.isdir( - os.path.join(self.currentDir, l)), - grids) + grids = filter(lambda l: l not in C_IGNORE_GRIDS, os.listdir(self.currentDir)) + grids = filter(lambda l: os.path.isdir(os.path.join(self.currentDir, l)), grids) grids = sorted(grids, key=str.lower) for grid in grids: if not os.path.exists(os.path.join(self.currentDir, grid)): - self.logger.write(self.write_test_margin(1), 3) - self.logger.write(UTS.red( - "grid %s does not exist\n" % grid), 3, False) + self.logger.info(self.write_test_margin(1)) + self.logger.error("grid %s does not exist" % grid)) else: self.currentgrid = grid self.run_grid_tests() @@ -805,7 +790,6 @@ class Test: if len(script) == 0: return - self.logger.write("\n", 2, False) if not os.path.exists(script): self.logger.warning("script not found: %s" % script) else: @@ -827,22 +811,20 @@ class Test: # calculate total execution time totalTime = datetime.datetime.now() - initTime totalTime -= datetime.timedelta(microseconds=totalTime.microseconds) - self.logger.write("\n\n" + _("=== END TESTS %s\n") % str(totalTime)) + self.logger.info("\n\n" + _("=== END TESTS %s\n") % str(totalTime)) # Start the tests self.run_script('test_cleanup') - self.logger.write("\n", 2, False) # evaluate results - res_count = "(%d/%d)" % \ - (self.nb_succeed, self.nb_run - self.nb_acknoledge) - + res_count = "(%d/%d)" % (self.nb_succeed, self.nb_run - self.nb_acknoledge) res_out = _("Tests Results: (%d/%d)\n") % (self.nb_succeed, self.nb_run) + if self.nb_succeed == self.nb_run: - res_out = UTS.green(res_out) else: res_out = UTS.red(res_out) + self.logger.info(res_out) if self.nb_timeout > 0: