From: Serge Rehbinder Date: Tue, 16 Feb 2016 10:42:13 +0000 (+0100) Subject: LOG : Add full option, logs correspond to the application X-Git-Tag: sprint-02bis~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a368c5b187ddf4b6e520eb6fba1042bbecd55868;p=tools%2Fsat.git LOG : Add full option, logs correspond to the application --- diff --git a/commands/log.py b/commands/log.py index a6ba331..e05f247 100644 --- a/commands/log.py +++ b/commands/log.py @@ -10,6 +10,10 @@ import src # Define all possible option for log command : sat log 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. @@ -123,10 +127,15 @@ def run(args, runner, logger): 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 diff --git a/src/ElementTree.py b/src/ElementTree.py index d11ad7f..49a0643 100644 --- a/src/ElementTree.py +++ b/src/ElementTree.py @@ -370,7 +370,13 @@ class _ElementInterface: # @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. @@ -389,8 +395,14 @@ class _ElementInterface: # @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. @@ -1057,7 +1069,12 @@ class TreeBuilder: 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 @@ -1150,9 +1167,9 @@ class XMLTreeBuilder: 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 = {} diff --git a/src/internal_config/salomeTools.pyconf b/src/internal_config/salomeTools.pyconf index 9aa08bf..6cf2a29 100644 --- a/src/internal_config/salomeTools.pyconf +++ b/src/internal_config/salomeTools.pyconf @@ -4,5 +4,9 @@ INTERNAL : { sat_version : "5.0.0dev" + log : + { + notShownCommands : ["log"] + } } diff --git a/src/logger.py b/src/logger.py index 24b234a..42e328d 100644 --- a/src/logger.py +++ b/src/logger.py @@ -45,7 +45,7 @@ class Logger(object): 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): @@ -65,6 +65,9 @@ class Logger(object): 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="") @@ -141,8 +144,6 @@ class Logger(object): # 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 diff --git a/src/xmlManager.py b/src/xmlManager.py index 9c84cc1..7b383c7 100644 --- a/src/xmlManager.py +++ b/src/xmlManager.py @@ -93,11 +93,21 @@ class readXmlFile(object): 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 @@ -105,6 +115,8 @@ class readXmlFile(object): '''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: @@ -112,8 +124,40 @@ class readXmlFile(object): 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 @@ -121,16 +165,11 @@ def update_hat_xml(logDir, application=None): ''' # 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 @@ -140,8 +179,11 @@ def update_hat_xml(logDir, application=None): 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 diff --git a/src/xsl/hat.xsl b/src/xsl/hat.xsl index 7fea550..2e33907 100644 --- a/src/xsl/hat.xsl +++ b/src/xsl/hat.xsl @@ -29,18 +29,18 @@

- -

Logs of commands without application

+ +

Logs of application

- Logs of application + General Logs

- + @@ -53,6 +53,7 @@ +
CommanddatetimeCommanddatetimeapplication