]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
add history in job reports
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 3 Oct 2016 14:29:21 +0000 (16:29 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 3 Oct 2016 14:29:21 +0000 (16:29 +0200)
commands/config.py
commands/jobs.py
src/xmlManager.py
src/xsl/jobs_board_report.xsl

index 0f3777cc284b37a6760623fdbe1aa2ce2e685692..a330d4630e32a7e6df0fcdd990d832d1d7a21d9a 100644 (file)
@@ -607,39 +607,44 @@ def show_product_info(config, name, logger):
         return
     
     # information on compilation
-    logger.write("\n", 2)
-    logger.write(src.printcolors.printcLabel("compile:") + "\n", 2)
-    src.printcolors.print_value(logger, 
-                                "compilation method", 
-                                pinfo.build_source, 
-                                2)
-    
-    if pinfo.build_source == "script" and "compil_script" in pinfo:
+    if src.product.product_compiles(pinfo):
+        logger.write("\n", 2)
+        logger.write(src.printcolors.printcLabel("compile:") + "\n", 2)
         src.printcolors.print_value(logger, 
-                                    "Compilation script", 
-                                    pinfo.compil_script
+                                    "compilation method", 
+                                    pinfo.build_source
                                     2)
+        
+        if pinfo.build_source == "script" and "compil_script" in pinfo:
+            src.printcolors.print_value(logger, 
+                                        "Compilation script", 
+                                        pinfo.compil_script, 
+                                        2)
+        
+        if 'nb_proc' in pinfo:
+            src.printcolors.print_value(logger, "make -j", pinfo.nb_proc, 2)
     
-    if 'nb_proc' in pinfo:
-        src.printcolors.print_value(logger, "make -j", pinfo.nb_proc, 2)
-
-    src.printcolors.print_value(logger, 
-                                "source dir", 
-                                check_path(pinfo.source_dir), 
-                                2)
-    if 'install_dir' in pinfo:
         src.printcolors.print_value(logger, 
-                                    "build dir", 
-                                    check_path(pinfo.build_dir), 
-                                    2)
-        src.printcolors.print_value(logger, 
-                                    "install dir", 
-                                    check_path(pinfo.install_dir), 
+                                    "source dir", 
+                                    check_path(pinfo.source_dir), 
                                     2)
+        if 'install_dir' in pinfo:
+            src.printcolors.print_value(logger, 
+                                        "build dir", 
+                                        check_path(pinfo.build_dir), 
+                                        2)
+            src.printcolors.print_value(logger, 
+                                        "install dir", 
+                                        check_path(pinfo.install_dir), 
+                                        2)
+        else:
+            logger.write("  " + 
+                         src.printcolors.printcWarning(_("no install dir")) + 
+                         "\n", 2)
     else:
-        logger.write("  " + 
-                     src.printcolors.printcWarning(_("no install dir")) + 
-                     "\n", 2)
+        logger.write("\n", 2)
+        msg = _("This product does not compile")
+        logger.write("%s\n" % msg, 2)
 
     # information on environment
     logger.write("\n", 2)
index 90be9793052c0f5eff3c6dde245124496bd0ca2f..66392da96c7d89f4dc46961338ec96df933758a9 100644 (file)
@@ -22,9 +22,11 @@ import time
 import csv
 import shutil
 import itertools
+import re
 import paramiko
 
 import src
+from _ast import Expression
 
 STYLESHEET_GLOBAL = "jobs_global_report.xsl"
 STYLESHEET_BOARD = "jobs_board_report.xsl"
@@ -800,8 +802,8 @@ class Jobs(object):
                     self.logger.write('\r%s%s%s %s' % 
                         (begin_line,
                          endline,
-                         src.printcolors.printc(src.OK_STATUS),
-                         _("Copy of SAT failed")), 3)
+                         src.printcolors.printc(src.KO_STATUS),
+                         _("Copy of SAT failed: %s" % res_copy)), 3)
             else:
                 self.logger.write('\r%s' % 
                                   ((len(begin_line)+len(endline)+20) * " "), 3)
@@ -1051,7 +1053,9 @@ class Gui(object):
         # The path of the global xml file
         self.xml_dir_path = xml_dir_path
         # Initialize the xml files
-        xml_global_path = os.path.join(self.xml_dir_path, "global_report.xml")
+        self.global_name = "global_report"
+        xml_global_path = os.path.join(self.xml_dir_path,
+                                       self.global_name + ".xml")
         self.xml_global_file = src.xmlManager.XmlLogFile(xml_global_path,
                                                          "JobsReport")
         # The xml files that corresponds to the boards.
@@ -1059,11 +1063,17 @@ class Gui(object):
         self.d_xml_board_files = {}
         # Create the lines and columns
         self.initialize_boards(l_jobs, l_jobs_not_today)
+        # Find history for each job
+        self.history = {}
+        self.find_history(l_jobs, l_jobs_not_today)
         
         # Write the xml file
         self.update_xml_files(l_jobs)
     
     def add_xml_board(self, name):
+        '''Add a board to the board list   
+        :param name str: the board name
+        '''
         xml_board_path = os.path.join(self.xml_dir_path, name + ".xml")
         self.d_xml_board_files[name] =  src.xmlManager.XmlLogFile(
                                                     xml_board_path,
@@ -1197,7 +1207,46 @@ class Gui(object):
                                             "job",
                                             attrib={"distribution" : row,
                                                     "application" : column })
-    
+
+    def find_history(self, l_jobs, l_jobs_not_today):
+        """find, for each job, in the existent xml boards the results for the 
+           job. Store the results in the dictionnary self.history = {name_job : 
+           list of (date, status, list links)}
+        
+        :param l_jobs List: the list of jobs to run today   
+        :param l_jobs_not_today List: the list of jobs that do not run today
+        """
+        # load the all the history
+        expression = "^[0-9]{8}_+[0-9]{6}_" + self.global_name + ".xml$"
+        oExpr = re.compile(expression)
+        # Get the list of global xml that are in the log directory
+        l_globalxml = []
+        for file_name in os.listdir(self.xml_dir_path):
+            if oExpr.search(file_name):
+                file_path = os.path.join(self.xml_dir_path, file_name)
+                global_xml = src.xmlManager.ReadXmlFile(file_path)
+                l_globalxml.append(global_xml)
+
+        # Construct the dictionnary self.history 
+        for job in l_jobs + l_jobs_not_today:
+            l_links = []
+            for global_xml in l_globalxml:
+                date = os.path.basename(global_xml.filePath).split("_")[0]
+                global_root_node = global_xml.xmlroot.find("jobs")
+                job_node = src.xmlManager.find_node_by_attrib(
+                                                              global_root_node,
+                                                              "job",
+                                                              "name",
+                                                              job.name)
+                if job_node:
+                    if job_node.find("remote_log_file_path") is not None:
+                        link = job_node.find("remote_log_file_path").text
+                        res_job = job_node.find("res").text
+                        if link != "nothing":
+                            l_links.append((date, res_job, link))
+                            
+            self.history[job.name] = l_links
+  
     def put_jobs_not_today(self, l_jobs_not_today, xml_node_jobs):
         '''Get all the first information needed for each file and write the 
            first version of the files   
@@ -1223,6 +1272,13 @@ class Gui(object):
             src.xmlManager.add_simple_node(xmlj, "user", job.machine.user)
             src.xmlManager.add_simple_node(xmlj, "sat_path",
                                                         job.machine.sat_path)
+            xml_history = src.xmlManager.add_simple_node(xmlj, "history")
+            for date, res_job, link in self.history[job.name]:
+                src.xmlManager.add_simple_node(xml_history,
+                                               "link",
+                                               text=link,
+                                               attrib={"date" : date,
+                                                       "res" : res_job})
 
     def parse_csv_boards(self, today):
         """ Parse the csv file that describes the boards to produce and fill 
@@ -1317,6 +1373,14 @@ class Gui(object):
             src.xmlManager.add_simple_node(xmlj, "host", job.machine.host)
             src.xmlManager.add_simple_node(xmlj, "port", str(job.machine.port))
             src.xmlManager.add_simple_node(xmlj, "user", job.machine.user)
+            xml_history = src.xmlManager.add_simple_node(xmlj, "history")
+            for date, res_job, link in self.history[job.name]:
+                src.xmlManager.add_simple_node(xml_history,
+                                               "link",
+                                               text=link,
+                                               attrib={"date" : date,
+                                                       "res" : res_job})
+
             src.xmlManager.add_simple_node(xmlj, "sat_path",
                                            job.machine.sat_path)
             src.xmlManager.add_simple_node(xmlj, "application", job.application)
index c125c5124999487eb06cf2eba62fb16a012c9c7b..78e84e7d8c9054731b245f7af595a186c3e16c05 100644 (file)
@@ -146,7 +146,7 @@ class ReadXmlFile(object):
         :rtype: str
         '''
         return self.xmlroot.find(node).text
-
+    
 def add_simple_node(root_node, node_name, text=None, attrib={}):
     '''Add a node with some attibutes and text to the root node.
 
@@ -170,6 +170,26 @@ def append_node_attrib(root_node, attrib):
     '''
     root_node.attrib.update(attrib)
 
+def find_node_by_attrib(xmlroot, name_node, key, value):
+    '''Find the nfirst ode from xmlroot that has name name_node and that has in 
+       its attributes {key : value}. Return the node
+    
+    :param xmlroot etree.Element: the Etree element where to search
+    :param name_node str: the name of node to search
+    :param key str: the key to search
+    :param value str: the value to search
+    :return: the found node
+    :rtype: xmlroot etree.Element
+    '''
+    l_nodes =  xmlroot.findall(name_node)
+    for node in l_nodes:
+        if key not in node.attrib.keys():
+            continue
+        if node.attrib[key] == value:
+            return node
+    return None
+    
+
 def write_report(filename, xmlroot, stylesheet):
     """Writes a report file from a XML tree.
     
@@ -185,4 +205,5 @@ def write_report(filename, xmlroot, stylesheet):
     if len(stylesheet) > 0:
         f.write("<?xml-stylesheet type='text/xsl' href='%s'?>\n" % stylesheet)
     f.write(etree.tostring(xmlroot, encoding='utf-8'))
-    f.close()
\ No newline at end of file
+    f.close()   
+    
\ No newline at end of file
index 2d6c93e90fd7e91791b60777c53f5517a96603ff..aae3b77e17868154841840742b0134c53e072305 100644 (file)
     .label        { font-weight: bold; }
 
     <!-- styles for links in matrix -->
-    .OK2          { color:#00AA00; }
-    .KO2          { color:#FF0000; }
-    .KF2          { color:#FF8000; }
-    .NA2          { color:#BBBBBB; }
-    .TO2          { color:GoldenRod; }
+    .OK2          { color:#00AA00; font-weight: normal;}
+    .KO2          { color:#FF0000; font-weight: normal;}
+    .KF2          { color:#FF8000; font-weight: normal;}
+    .NA2          { color:#BBBBBB; font-weight: normal;}
+    .TO2          { color:GoldenRod; font-weight: normal;}
     .RUNNING2     { color:LightSeaGreen; font-weight: bold; }
     .OK2day       { color:#00AA00; font-weight: bold; }
     .KO2day       { color:#FF0000; font-weight: bold; }
                  <br/>
                  <h4>User : </h4><xsl:value-of select="//JobsReport/jobs/job[@name=$curr_job_name]/user"/>
                  <br/>
+                 <!-- Display history -->
+                 <h4>History : </h4>
+                 <br/>
+                 <xsl:for-each select="//JobsReport/jobs/job[@name=$curr_job_name]/history/link">
+                   <h4>
+                     <a>
+                       <xsl:attribute name="title">remote log</xsl:attribute>
+                       <xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute>
+                       <xsl:if test="@res='0'">
+                           <xsl:attribute name="class">OK2</xsl:attribute>
+                       </xsl:if>
+                       <xsl:if test="@res!='0'">
+                           <xsl:attribute name="class">KO2</xsl:attribute>
+                       </xsl:if>
+                       <xsl:value-of select="@date"/>
+                     </a>
+                   </h4>
+                   <br/>
+                 </xsl:for-each>
                  <h4>salomeTools path : </h4><xsl:value-of select="//JobsReport/jobs/job[@name=$curr_job_name]/sat_path"/>
                  <br/>
                  <h4>After : </h4>