X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Flogger.py;h=fe65a423bcbfce261abf71dee35a9dc5e4577809;hb=8e00fa7ac6ec81450617526f0ae96126ca422fd7;hp=94f81d609b093e952caa07538e245de283f8400e;hpb=f44ef88e646f05a4b911fb42f9af7986af64d3d4;p=tools%2Fsat.git diff --git a/src/logger.py b/src/logger.py index 94f81d6..fe65a42 100755 --- a/src/logger.py +++ b/src/logger.py @@ -22,6 +22,7 @@ Implements the classes and method relative to the logging import sys import os +import stat import datetime import re import tempfile @@ -36,6 +37,8 @@ import src.debug as DBG log_macro_command_file_expression = "^[0-9]{8}_+[0-9]{6}_+.*\.xml$" log_all_command_file_expression = "^.*[0-9]{8}_+[0-9]{6}_+.*\.xml$" +verbose = True # cvw TODO + class Logger(object): """\ Class to handle log mechanism. @@ -70,8 +73,22 @@ class Logger(object): # the external commands calls (cmake, make, git clone, etc...) txtFileName = prefix + hour_command_host + ".txt" txtFilePath = os.path.join(log_dir, "OUT", txtFileName) - - src.ensure_path_exists(os.path.dirname(logFilePath)) + + aDirLog = os.path.dirname(logFilePath) + if not os.path.exists(aDirLog): + print("create log dir %s" % aDirLog) + src.ensure_path_exists(aDirLog) + # sometimes other users make 'sat log' and create hat.xml file... + os.chmod(aDirLog, + stat.S_IRUSR | + stat.S_IRGRP | + stat.S_IROTH | + stat.S_IWUSR | + stat.S_IWGRP | + stat.S_IWOTH | + stat.S_IXUSR | + stat.S_IXGRP | + stat.S_IXOTH) src.ensure_path_exists(os.path.dirname(txtFilePath)) # The path of the log files (one for sat traces, and the other for @@ -129,7 +146,7 @@ class Logger(object): self.config.VARS.user}) # The time when command was launched Y, m, dd, H, M, S = date_to_datetime(self.config.VARS.datehour) - date_hour = "%2s/%2s/%4s %2sh%2sm%2ss" % (dd, m, Y, H, M, S) + date_hour = "%4s/%2s/%2s %2sh%2sm%2ss" % (Y, m, dd, H, M, S) self.xmlFile.append_node_attrib("Site", attrib={"beginTime" : date_hour}) # The application if any @@ -382,17 +399,22 @@ def show_command_log(logFilePath, cmd, application, notShownCommands): sys.stdout.write(printcolors.printcWarning("%s\n%s\n" % (msg, e))) return False, None, None - if 'application' in logFileXml.xmlroot.keys(): - appliLog = logFileXml.xmlroot.get('application') - launched_cmd = logFileXml.xmlroot.find('Site').attrib['launchedCommand'] - # if it corresponds, then the log has to be shown - if appliLog == application: - return True, appliLog, launched_cmd - elif application != 'None': - return False, appliLog, launched_cmd - - return True, appliLog, launched_cmd - + try: + if 'application' in logFileXml.xmlroot.keys(): + appliLog = logFileXml.xmlroot.get('application') + launched_cmd = logFileXml.xmlroot.find('Site').attrib['launchedCommand'] + # if it corresponds, then the log has to be shown + if appliLog == application: + return True, appliLog, launched_cmd + elif application != 'None': + return False, appliLog, launched_cmd + + return True, appliLog, launched_cmd + except Exception as e: + msg = _("WARNING: the log file %s cannot be parsed:" % logFilePath) + sys.stdout.write(printcolors.printcWarning("%s\n%s\n" % (msg, e))) + return False, None, None + if application == 'None': return True, None, None @@ -450,8 +472,7 @@ def update_hat_xml(logDir, application=None, notShownCommands = []): """ # Create an instance of XmlLogFile class to create hat.xml file xmlHatFilePath = os.path.join(logDir, 'hat.xml') - xmlHat = src.xmlManager.XmlLogFile(xmlHatFilePath, - "LOGlist", {"application" : application}) + xmlHat = src.xmlManager.XmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application}) # parse the log directory to find all the command logs, # then add it to the xml file lLogFile = list_log_file(logDir, log_macro_command_file_expression) @@ -471,6 +492,15 @@ def update_hat_xml(logDir, application=None, notShownCommands = []): # Write the file on the hard drive xmlHat.write_tree('hat.xsl') + # Sometimes other users will make 'sat log' and update this file + os.chmod(xmlHatFilePath, + stat.S_IRUSR | + stat.S_IRGRP | + stat.S_IROTH | + stat.S_IWUSR | + stat.S_IWGRP | + stat.S_IWOTH ) + # TODO for future