# Define all possible option for log command : sat log <options>
parser = src.options.Options()
parser.add_option('t', 'terminal', 'boolean', 'terminal', "Terminal log.")
+parser.add_option('l', 'last', 'boolean', 'last', "Show the log of the last launched command.")
+parser.add_option('f', 'full', 'boolean', 'full', "Show the logs of ALL launched commands.")
+parser.add_option('c', 'clean', 'int', 'clean', "Erase the n most ancient log files.")
+
def show_log_command_in_terminal(filePath, logger):
'''Print the contain of filePath. It contains a command log in xml format.
shutil.copy2(xslCommand, logDir)
shutil.copy2(xslHat, logDir)
shutil.copy2(imgLogo, logDir)
-
+
+ # determine the commands to show in the hat log
+ notShownCommands = runner.cfg.INTERNAL.log.notShownCommands
+ if options.full:
+ notShownCommands = []
+
# Create or update the hat xml that gives access to all the commands log files
xmlHatFilePath = os.path.join(logDir, 'hat.xml')
- src.xmlManager.update_hat_xml(runner.cfg.SITE.log.logDir, runner.cfg.VARS.application)
+ src.xmlManager.update_hat_xml(runner.cfg.SITE.log.logDir, application = runner.cfg.VARS.application, notShownCommands = notShownCommands)
# open the hat xml in the user editor
src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath, logger)
\ No newline at end of file
# @defreturn string or None
def get(self, key, default=None):
- return self.attrib.get(key, default)
+ res = self.attrib.get(key, default)
+ if not res:
+ res = self.attrib.get(key.encode(), default)
+ if isinstance(res, bytes):
+ return res.decode()
+ else:
+ return res
##
# Sets an element attribute.
# @defreturn list of strings
def keys(self):
- return self.attrib.keys()
-
+ res = []
+ for key in self.attrib.keys():
+ if isinstance(key, bytes):
+ res.append(key.decode())
+ else:
+ res.append(key)
+ return res
+
##
# Gets element attributes, as a sequence. The attributes are
# returned in an arbitrary order.
def _flush(self):
if self._data:
if self._last is not None:
- text = string.join(self._data, "")
+ text = ""
+ for item in self._data:
+ try:
+ text += item
+ except:
+ text += item.decode()
if self._tail:
assert self._last.tail is None, "internal error (tail)"
self._last.tail = text
parser.StartElementHandler = self._start_list
except AttributeError:
pass
- encoding = None
- if not parser.returns_unicode:
- encoding = "utf-8"
+ #encoding = None
+ #if not parser.returns_unicode:
+ # encoding = "utf-8"
# target.xml(encoding, None)
self._doctype = None
self.entity = {}
INTERNAL :
{
sat_version : "5.0.0dev"
+ log :
+ {
+ notShownCommands : ["log"]
+ }
}
self.logFileName = logFileName
self.logFilePath = logFilePath
- self.xmlFile = xmlManager.xmlLogFile(logFilePath, "SATcommand", attrib = {"command" : config.VARS.command})
+ self.xmlFile = xmlManager.xmlLogFile(logFilePath, "SATcommand", attrib = {"application" : config.VARS.application})
self.putInitialXMLFields()
def putInitialXMLFields(self):
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)
self.xmlFile.append_node_attrib("Site", attrib={"beginTime" : date_hour})
+ # The application if any
+ if "APPLICATION" in self.config:
+ self.xmlFile.append_node_attrib("Site", attrib={"application" : self.config.VARS.application})
# The initialization of the trace node
self.xmlFile.add_simple_node("Log",text="")
# Call the method to write the xml file on the hard drive
self.xmlFile.write_tree(stylesheet = "command.xsl")
- # Update the hat xml (that shows all logs) in order to make the new log visible on the main log page)
- src.xmlManager.update_hat_xml(self.config.SITE.log.logDir)
def date_to_datetime(date):
'''Little method that gets year, mon, day, hour , minutes and seconds from a str in format YYYYMMDD_HHMMSS
self.filePath = filePath
etree_inst = etree.parse(filePath)
self.xmlroot = etree_inst.parse(filePath)
+
+ def getRootAttrib(self):
+ '''Get the attibutes of the self.xmlroot
+
+ :return: The attributes of the root node
+ :rtype: dict
+ '''
+ return self.xmlroot.attrib
def get_attrib(self, node_name):
'''Get the attibutes of the node node_name in self.xmlroot
:param node_name str: the name of the node
+ :return: the attibutes of the node node_name in self.xmlroot
+ :rtype: dict
'''
return self.xmlroot.find(node_name).attrib
'''Get the text of the first node that has name that corresponds to the parameter node
:param node str: the name of the node from which get the text
+ :return: the text of the first node that has name that corresponds to the parameter node
+ :rtype: str
'''
# Loop on all root nodes
for field in self.xmlroot:
return field.text
return ''
+def showcommandLog(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
+
+ # Get the application of the log file
+ logFileXml = readXmlFile(logFilePath)
+ if 'application' in logFileXml.xmlroot.keys():
+ appliLog = logFileXml.xmlroot.get('application')
+ # if it corresponds, then the log has to be shown
+ if appliLog == application:
+ return True, appliLog
+ elif application != 'None':
+ return False, appliLog
+
+ return True, appliLog
+
+ if application == 'None':
+ return True, None
+
+ return False, None
+
-def update_hat_xml(logDir, application=None):
+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
'''
# Create an instance of xmlLogFile class to create hat.xml file
xmlHatFilePath = os.path.join(logDir, 'hat.xml')
- # If there is an application, add the attribute to the root node
- if application:
- xmlHat = xmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application})
- else:
- xmlHat = xmlLogFile(xmlHatFilePath, "LOGlist", {"application" : "NO"})
-
+ xmlHat = xmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application})
# parse the log directory to find all the command logs, then add it to the xml file
for fileName in os.listdir(logDir):
# YYYYMMDD_HHMMSS_namecmd.xml
- sExpr = "^[0-9]{8}_+[0-9]{6}_+.*.xml$"
+ sExpr = "^[0-9]{8}_+[0-9]{6}_+.*\.xml$"
oExpr = re.compile(sExpr)
if oExpr.search(fileName):
# get date and hour and format it
hour_not_formated = date_hour_cmd[1]
hour = "%s:%s:%s" % (hour_not_formated[0:2], hour_not_formated[2:4], hour_not_formated[4:6])
cmd = date_hour_cmd[2][:-len('.xml')]
- # add a node to the hat.xml file
- xmlHat.add_simple_node("LogCommand", text=fileName, attrib = {"date" : date, "hour" : hour, "cmd" : cmd})
+ showLog, cmdAppli = showcommandLog(os.path.join(logDir, fileName), cmd, application, notShownCommands)
+ #if cmd not in notShownCommands:
+ if showLog:
+ # add a node to the hat.xml file
+ xmlHat.add_simple_node("LogCommand", text=fileName, attrib = {"date" : date, "hour" : hour, "cmd" : cmd, "application" : cmdAppli})
# Write the file on the hard drive
xmlHat.write_tree('hat.xsl')
\ No newline at end of file
<body class="def" bgcolor="aliceblue">
<h1><img src="LOGO-SAT.png"/></h1>
<xsl:choose>
- <xsl:when test="LOGlist/@application='NO'">
- <h1>Logs of commands without application</h1>
+ <xsl:when test="not(LOGlist/@application='None')">
+ <h1>Logs of application <xsl:value-of select="LOGlist/@application"/></h1>
</xsl:when>
<xsl:otherwise>
<h1>
- Logs of application <xsl:value-of select="LOGlist/@application"/>
+ General Logs
</h1>
</xsl:otherwise>
</xsl:choose>
<table border="0">
<tr>
- <td width="100px">Command</td><td width="100px">date</td><td>time</td>
+ <td width="100px">Command</td><td width="100px">date</td><td width="100px">time</td><td>application</td>
</tr>
<xsl:for-each select="LOGlist/LogCommand">
<xsl:sort select="." order="descending" />
</td>
<td><xsl:value-of select="@date"/></td>
<td><xsl:value-of select="@hour"/></td>
+ <td><xsl:value-of select="@application"/></td>
</tr>
</xsl:for-each>
</table>