+ return Y, m, dd, H, M, S
+
+def timedelta_total_seconds(timedelta):
+ '''Little method to replace total_seconds from
+ datetime module in order to be compatible with old python versions
+
+ :param timedelta datetime.timedelta: The delta between two dates
+ :return: The number of seconds corresponding to timedelta.
+ :rtype: float
+ '''
+ return (
+ timedelta.microseconds + 0.0 +
+ (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6
+
+def show_command_log(logFilePath, cmd, application, notShownCommands):
+ '''Used in updateHatXml. Determine if the log xml file logFilePath
+ has to be shown or not in the hat log.
+
+ :param logFilePath str: the path to the command xml log file
+ :param cmd str: the command of the log file
+ :param application str: the application passed as parameter
+ to the salomeTools command
+ :param notShownCommands list: the list of commands
+ that are not shown by default
+
+ :return: True if cmd is not in notShownCommands and the application
+ in the log file corresponds to application
+ :rtype: boolean
+ '''
+ # When the command is not in notShownCommands, no need to go further :
+ # Do not show
+ if cmd in notShownCommands:
+ return False, None, None
+
+ # Get the application of the log file
+ 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, 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
+
+ if application == 'None':
+ return True, None, None
+
+ return False, None, None
+
+def list_log_file(dirPath, expression):
+ '''Find all files corresponding to expression in dirPath
+
+ :param dirPath str: the directory where to search the files
+ :param expression str: the regular expression of files to find
+ :return: the list of files path and informations about it
+ :rtype: list
+ '''
+ lRes = []
+ for fileName in os.listdir(dirPath):
+ # YYYYMMDD_HHMMSS_namecmd.xml
+ sExpr = expression
+ oExpr = re.compile(sExpr)
+ if oExpr.search(fileName):
+ file_name = fileName
+ if fileName.startswith("micro_"):
+ file_name = fileName[len("micro_"):]
+ # get date and hour and format it
+ date_hour_cmd_host = file_name.split('_')
+ date_not_formated = date_hour_cmd_host[0]
+ date = "%s/%s/%s" % (date_not_formated[6:8],
+ date_not_formated[4:6],
+ date_not_formated[0:4])
+ hour_not_formated = date_hour_cmd_host[1]
+ hour = "%s:%s:%s" % (hour_not_formated[0:2],
+ hour_not_formated[2:4],
+ hour_not_formated[4:6])
+ if len(date_hour_cmd_host) < 4:
+ cmd = date_hour_cmd_host[2][:-len('.xml')]
+ host = ""
+ else:
+ cmd = date_hour_cmd_host[2]
+ host = date_hour_cmd_host[3][:-len('.xml')]
+ lRes.append((os.path.join(dirPath, fileName),
+ date_not_formated,
+ date,
+ hour_not_formated,
+ hour,
+ cmd,
+ host))
+ return lRes
+
+def update_hat_xml(logDir, application=None, notShownCommands = []):
+ '''Create the xml file in logDir that contain all the xml file
+ and have a name like YYYYMMDD_HHMMSS_namecmd.xml
+
+ :param logDir str: the directory to parse
+ :param application str: the name of the application if there is any
+ '''
+ # 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})
+ # 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)
+ for filePath, __, date, __, hour, cmd, __ in lLogFile:
+ showLog, cmdAppli, full_cmd = show_command_log(filePath, cmd,
+ application, notShownCommands)
+ #if cmd not in notShownCommands:
+ if showLog:
+ # add a node to the hat.xml file
+ xmlHat.add_simple_node("LogCommand",
+ text=os.path.basename(filePath),
+ attrib = {"date" : date,
+ "hour" : hour,
+ "cmd" : cmd,
+ "application" : cmdAppli,
+ "full_command" : full_cmd})
+
+ # Write the file on the hard drive
+ xmlHat.write_tree('hat.xsl')
\ No newline at end of file