+ cfgManager = CONFIG.ConfigManager()
+ self.cfg = cfgManager.get_config(datadir=self.datadir,
+ application=appliToLoad,
+ options=self.options,
+ command=__nameCmd__)
+
+ # Set the verbose mode if called
+ if verbose > -1:
+ verbose_save = self.options.output_verbose_level
+ self.options.__setattr__("output_verbose_level", verbose)
+
+ # Set batch mode if called
+ if batch:
+ batch_save = self.options.batch
+ self.options.__setattr__("batch", True)
+
+ # set output level
+ 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
+ micro_command = False
+ if logger_add_link:
+ micro_command = True
+ logger_command = src.logger.Logger(self.cfg,
+ silent_sysstd=silent,
+ all_in_terminal=self.options.all_in_terminal,
+ micro_command=micro_command)
+
+ # Check that the path given by the logs_paths_in_file option
+ # is a file path that can be written
+ if self.options.logs_paths_in_file and not micro_command:
+ try:
+ self.options.logs_paths_in_file = os.path.abspath(
+ self.options.logs_paths_in_file)
+ dir_file = os.path.dirname(self.options.logs_paths_in_file)
+ if not os.path.exists(dir_file):
+ os.makedirs(dir_file)
+ if os.path.exists(self.options.logs_paths_in_file):
+ os.remove(self.options.logs_paths_in_file)
+ file_test = open(self.options.logs_paths_in_file, "w")
+ file_test.close()
+ except Exception as e:
+ msg = _("WARNING: the logs_paths_in_file option will "
+ "not be taken into account.\nHere is the error:")
+ logger_command.write("%s\n%s\n\n" % (
+ src.printcolors.printcWarning(msg),
+ str(e)))
+ self.options.logs_paths_in_file = None
+
+
+ # do nothing more if help is True
+ if self.options.help:
+ return 0
+
+ options_launched = ""
+ res = None
+ try:
+ # Execute the hooks (if there is any)
+ # and run method of the command
+ self.run_hook(__nameCmd__, C_PRE_HOOK, logger_command)
+ res = __module__.run(argv, self, logger_command)
+ self.run_hook(__nameCmd__, C_POST_HOOK, logger_command)
+ if res is None:
+ res = 0
+
+ except src.SatException as e:
+ # for sat exception do not display the stack, unless debug mode is set
+ logger_command.write("\n***** ", 1)
+ logger_command.write(src.printcolors.printcError(
+ "salomeTools ERROR: sat %s" % __nameCmd__), 1)
+ logger_command.write(" *****\n", 1)
+ print(e.message)
+ if self.options.debug_mode:
+ logger_command.write("\n" + DBG.format_exception("") + "\n", 1)
+
+ except Exception as e:
+ # here we print the stack in addition
+ logger_command.write("\n***** ", 1)
+ logger_command.write(src.printcolors.printcError(
+ "salomeTools ERROR: sat %s" % __nameCmd__), 1)
+
+ logger_command.write("\n" + DBG.format_exception("") + "\n", 1)
+
+
+ finally:
+ # set res if it is not set in the command
+ if res is None:
+ res = 1
+
+ # come back to the original global options
+ if options:
+ options_launched = get_text_from_options(self.options)
+ self.options = options_save
+
+ # come back in the original batch mode if
+ # batch argument was called
+ if batch:
+ self.options.__setattr__("batch", batch_save)
+
+ # come back in the original verbose mode if
+ # verbose argument was called
+ if verbose > -1:
+ self.options.__setattr__("output_verbose_level",
+ verbose_save)
+ # put final attributes in xml log file
+ # (end time, total time, ...) and write it
+ launchedCommand = ' '.join([self.cfg.VARS.salometoolsway +
+ os.path.sep +
+ 'sat',
+ options_launched,
+ __nameCmd__,
+ ' '.join(argv_0)])
+ # TODO may be no need as call escapeSequence xml
+ launchedCommand = launchedCommand.replace('"', "'")
+
+ # Add a link to the parent command
+ if logger_add_link is not None:
+ logger_add_link.add_link(logger_command.logFileName,
+ __nameCmd__,
+ res,
+ launchedCommand)
+ logger_add_link.l_logFiles += logger_command.l_logFiles
+
+ # Put the final attributes corresponding to end time and
+ # Write the file to the hard drive
+ logger_command.end_write(
+ {"launchedCommand" : launchedCommand})
+
+ if res != 0:
+ res = 1
+
+ # print the log file path if
+ # the maximum verbose mode is invoked
+ if not micro_command:
+ logger_command.write("\nPath to the xml log file :\n",
+ 5)
+ logger_command.write("%s\n\n" % src.printcolors.printcInfo(
+ logger_command.logFilePath), 5)
+
+ # If the logs_paths_in_file was called, write the result
+ # and log files in the given file path
+ if self.options.logs_paths_in_file and not micro_command:
+ file_res = open(self.options.logs_paths_in_file, "w")
+ file_res.write(str(res) + "\n")
+ for i, filepath in enumerate(logger_command.l_logFiles):
+ file_res.write(filepath)
+ if i < len(logger_command.l_logFiles):
+ file_res.write("\n")
+ file_res.flush()