]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
try to be cdash like in xml log files
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Thu, 11 Feb 2016 15:37:44 +0000 (16:37 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Thu, 11 Feb 2016 15:37:44 +0000 (16:37 +0100)
src/logger.py
src/xmlManager.py
src/xsl/command.xsl

index f22a5c296a3b952f8ba295d12af5a8e4e24ccc26..cfa78ffd4e79495da2b30e21db7cdbbb416cdf4d 100644 (file)
@@ -54,21 +54,21 @@ class Logger(object):
         '''Method called at class initialization : Put all fields corresponding to the command context (user, time, ...)
         '''
         # command name
-        self.xmlFile.add_simple_node("field", text=self.config.VARS.command , attrib={"name" : "command"})
+        self.xmlFile.add_simple_node("Site", attrib={"command" : self.config.VARS.command})
         # version of salomeTools
-        self.xmlFile.add_simple_node("field", text=self.config.INTERNAL.sat_version , attrib={"name" : "satversion"})
+        self.xmlFile.append_node_attrib("Site", attrib={"satversion" : self.config.INTERNAL.sat_version})
         # machine name on which the command has been launched
-        self.xmlFile.add_simple_node("field", text=self.config.VARS.hostname , attrib={"name" : "hostname"})
+        self.xmlFile.append_node_attrib("Site", attrib={"hostname" : self.config.VARS.hostname})
         # Distribution of the machine
-        self.xmlFile.add_simple_node("field", text=self.config.VARS.dist , attrib={"name" : "OS"})
+        self.xmlFile.append_node_attrib("Site", attrib={"OS" : self.config.VARS.dist})
         # The user that have launched the command
-        self.xmlFile.add_simple_node("field", text=self.config.VARS.user , attrib={"name" : "user"})
+        self.xmlFile.append_node_attrib("Site", attrib={"user" : 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)
-        self.xmlFile.add_simple_node("field", text=date_hour , attrib={"name" : "beginTime"})
+        self.xmlFile.append_node_attrib("Site", attrib={"beginTime" : date_hour})
         # The initialization of the trace node
-        self.xmlFile.add_simple_node("traces",text="")
+        self.xmlFile.add_simple_node("Log",text="")
 
     def write(self, message, level=None, screenOnly=False):
         '''the function used in the commands that will print in the terminal and the log file.
@@ -79,7 +79,7 @@ class Logger(object):
         '''
         # do not write message starting with \r to log file
         if not message.startswith("\r") and not screenOnly:
-            self.xmlFile.append_node("traces", printcolors.cleancolor(message))
+            self.xmlFile.append_node_text("Log", printcolors.cleancolor(message))
 
         # get user or option output level
         current_output_level = self.config.USER.output_level
@@ -102,7 +102,7 @@ class Logger(object):
         :param message str: The message to print.
         '''
         # Print in the log file
-        self.xmlFile.append_node("traces", _('ERROR:') + message)
+        self.xmlFile.append_node_text("traces", _('ERROR:') + message)
 
         # Print in the terminal and clean colors if the terminal is redirected by user
         if not ('isatty' in dir(sys.stderr) and sys.stderr.isatty()):
@@ -139,8 +139,8 @@ 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')
-        self.xmlFile.add_simple_node("field", text=endtime , attrib={"name" : "endTime"})
-        self.xmlFile.add_simple_node("field", text="%ih%im%is" % (hours, minutes, seconds) , attrib={"name" : "Total Time"})
+        self.xmlFile.append_node_attrib("Site", attrib={"endTime" : endtime})
+        self.xmlFile.append_node_attrib("Site", attrib={"TotalTime" : "%ih%im%is" % (hours, minutes, seconds)})
         
         # Call the method to write the xml file on the hard drive
         self.xmlFile.write_tree(stylesheet = "command.xsl")
index ad454d8b6e9b313beea9e742d26067179434871e..5483c7048188e929bdf9882564506421d52730c7 100644 (file)
@@ -62,7 +62,7 @@ class xmlLogFile(object):
         self.xmlroot.append(n)
         return n
     
-    def append_node(self, node_name, text):
+    def append_node_text(self, node_name, text):
         '''Append a new text to the node that has node_name as name
         
         :param node_name str: The name of the node on which append text
@@ -74,6 +74,14 @@ class xmlLogFile(object):
                 # append the text
                 field.text += text
 
+    def append_node_attrib(self, node_name, attrib):
+        '''Append a new attributes to the node that has node_name as name
+        
+        :param node_name str: The name of the node on which append text
+        :param attrib dixt: The attrib to append
+        '''
+        self.xmlroot.find(node_name).attrib.update(attrib)
+
 class readXmlFile(object):
     '''Class to manage reading of an xml log file
     '''
index 7d0507aa9ca03e640035eb2f18eb48b0e1893ff2..76c3c489002673ae9b36d88ac3b5ee1fdebceac3 100644 (file)
                <h1><img src="LOGO-SAT.png"/></h1>
                <table border="1">
                        <tr>
-                               <xsl:for-each select="SATcommand/field">
+                               <xsl:for-each select="SATcommand/Site/@*">
                                        <td bgcolor="LightBlue">
-                                               <th><xsl:value-of select="@name"/></th>
+                                               <th><xsl:value-of select="name(.)"/></th>
                                        </td>
                                </xsl:for-each>
                        </tr>
                        <tr>
-                               <xsl:for-each select="SATcommand/field">        
+                               <xsl:for-each select="SATcommand/Site/@*">      
                                        <td bgcolor="Beige"><xsl:value-of select="."/></td>
                                </xsl:for-each>
                        </tr>
                </table>
                <h1>command's traces :</h1>
-               <PRE><xsl:value-of select="SATcommand/traces"/></PRE>
+               <PRE><xsl:value-of select="SATcommand/Log"/></PRE>
        </body>
 </xsl:template>
-</xsl:stylesheet>
+</xsl:stylesheet>
\ No newline at end of file