X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Flogger.py;h=297cba019ab41cafcc0c6addadc5e43c3877869c;hb=bde164334532578b05830dea712d5730d8599037;hp=40c01367e7c7575e15d21fd601062f5607c66c14;hpb=a13a4b1a040e45dae0eec813f20ec6a4ee43e78a;p=tools%2Fsat.git diff --git a/src/logger.py b/src/logger.py index 40c0136..297cba0 100644 --- a/src/logger.py +++ b/src/logger.py @@ -45,11 +45,11 @@ class Logger(object): # Construct xml log file location for sat prints. logFileName = config.VARS.datehour + "_" + config.VARS.command + ".xml" - logFilePath = os.path.join(config.SITE.log.log_dir, logFileName) + logFilePath = os.path.join(config.USER.log_dir, logFileName) # Construct txt file location in order to log # the external commands calls (cmake, make, git clone, etc...) txtFileName = config.VARS.datehour + "_" + config.VARS.command + ".txt" - txtFilePath = os.path.join(config.SITE.log.log_dir, "OUT", txtFileName) + txtFilePath = os.path.join(config.USER.log_dir, "OUT", txtFileName) src.ensure_path_exists(os.path.dirname(logFilePath)) src.ensure_path_exists(os.path.dirname(txtFilePath)) @@ -115,6 +115,27 @@ class Logger(object): # command self.xmlFile.add_simple_node("Links") + def add_link(self, + log_file_name, + command_name, + command_res, + full_launched_command): + '''Add a link to another log file. + + :param log_file_name str: The file name of the link. + :param command_name str: The name of the command linked. + :param command_res str: The result of the command linked. "0" or "1" + :parma full_launched_command str: The full lanch command + ("sat command ...") + ''' + xmlLinks = self.xmlFile.xmlroot.find("Links") + src.xmlManager.add_simple_node(xmlLinks, + "link", + text = log_file_name, + attrib = {"command" : command_name, + "passed" : command_res, + "launchedCommand" : full_launched_command}) + def write(self, message, level=None, screenOnly=False): '''the function used in the commands that will print in the terminal and the log file. @@ -143,6 +164,7 @@ class Logger(object): 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. @@ -185,7 +207,7 @@ class Logger(object): seconds = total_time - hours*3600 - minutes*60 # Add the fields corresponding to the end time # and the total time of command - endtime = dt.strftime('%d/%Y/%m %Hh%Mm%Ss') + endtime = dt.strftime('%Y/%m/%d %Hh%Mm%Ss') self.xmlFile.append_node_attrib("Site", attrib={"endTime" : endtime}) self.xmlFile.append_node_attrib("Site", attrib={"TotalTime" : "%ih%im%is" % (hours, minutes, seconds)}) @@ -197,7 +219,7 @@ class Logger(object): self.xmlFile.write_tree(stylesheet = "command.xsl") # Dump the config in a pyconf file in the log directory - logDir = self.config.SITE.log.log_dir + logDir = self.config.USER.log_dir dumpedPyconfFileName = (self.config.VARS.datehour + "_" + self.config.VARS.command @@ -257,7 +279,12 @@ def show_command_log(logFilePath, cmd, application, notShownCommands): return False, None # Get the application of the log file - logFileXml = src.xmlManager.ReadXmlFile(logFilePath) + try: + logFileXml = src.xmlManager.ReadXmlFile(logFilePath) + except Exception as e: + msg = _("WARNING: the log file %s cannot be read:" % logFilePath) + sys.stdout.write(printcolors.printcWarning("%s\n%s\n" % (msg, e))) + return False, None if 'application' in logFileXml.xmlroot.keys(): appliLog = logFileXml.xmlroot.get('application')