Salome HOME
Separating the test command from the other commands in the boards made by the jobs...
[tools/sat.git] / commands / jobs.py
index ce9a19d918b0cfd24ca1d1c7d210ee7bcadf006c..06602f2d941364c37cd0c457a26ed23b023b8936 100644 (file)
@@ -137,8 +137,9 @@ class Machine(object):
             self.put_dir(sat_local_path, self.sat_path, filters = ['.git'])
             # put the job configuration file in order to make it reachable 
             # on the remote machine
+            remote_job_file_name = ".%s" % os.path.basename(job_file)
             self.sftp.put(job_file, os.path.join(self.sat_path,
-                                                 ".jobs_command_file.pyconf"))
+                                                 remote_job_file_name))
         except Exception as e:
             res = str(e)
             self._connection_successful = False
@@ -236,8 +237,18 @@ class Machine(object):
 class Job(object):
     '''Class to manage one job
     '''
-    def __init__(self, name, machine, application, board, 
-                 commands, timeout, config, logger, after=None, prefix=None):
+    def __init__(self,
+                 name,
+                 machine,
+                 application,
+                 board, 
+                 commands,
+                 timeout,
+                 config,
+                 job_file_path,
+                 logger,
+                 after=None,
+                 prefix=None):
 
         self.name = name
         self.machine = machine
@@ -267,7 +278,8 @@ class Job(object):
 
         self.out = ""
         self.err = ""
-               
+        
+        self.name_remote_jobs_pyconf = ".%s" % os.path.basename(job_file_path)
         self.commands = commands
         self.command = (os.path.join(self.machine.sat_path, "sat") +
                         " -l " +
@@ -275,7 +287,7 @@ class Job(object):
                                      "list_log_files.txt") +
                         " job --jobs_config " + 
                         os.path.join(self.machine.sat_path,
-                                     ".jobs_command_file.pyconf") +
+                                     self.name_remote_jobs_pyconf) +
                         " --name " +
                         self.name)
         if prefix:
@@ -670,6 +682,7 @@ class Jobs(object):
                    cmmnds,
                    timeout,
                    self.runner.cfg,
+                   self.job_file_path,
                    self.logger,
                    after = after,
                    prefix = prefix)
@@ -1043,7 +1056,13 @@ class Gui(object):
        see the jobs states
     '''
    
-    def __init__(self, xml_dir_path, l_jobs, l_jobs_not_today, prefix, file_boards=""):
+    def __init__(self,
+                 xml_dir_path,
+                 l_jobs,
+                 l_jobs_not_today,
+                 prefix,
+                 logger,
+                 file_boards=""):
         '''Initialization
         
         :param xml_dir_path str: The path to the directory where to put 
@@ -1053,6 +1072,9 @@ class Gui(object):
         :param file_boards str: the file path from which to read the
                                    expected boards
         '''
+        # The logging instance
+        self.logger = logger
+        
         # The prefix to add to the xml files : date_hour
         self.prefix = prefix
         
@@ -1084,7 +1106,7 @@ class Gui(object):
 
         # Create the lines and columns
         self.initialize_boards(l_jobs, l_jobs_not_today)
-        
+
         # Write the xml file
         self.update_xml_files(l_jobs)
     
@@ -1277,8 +1299,15 @@ class Gui(object):
         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)
+                try:
+                    global_xml = src.xmlManager.ReadXmlFile(file_path)
+                    l_globalxml.append(global_xml)
+                except Exception as e:
+                    msg = _("\nWARNING: the file %s can not be read, it will be "
+                            "ignored\n%s" % (file_path, e))
+                    self.logger.write("%s\n" % src.printcolors.printcWarning(
+                                                                        msg), 5)
+                    
 
         # Construct the dictionnary self.history 
         for job in l_jobs + l_jobs_not_today:
@@ -1472,6 +1501,12 @@ class Gui(object):
                 src.xmlManager.add_simple_node(xmlj,
                                                "remote_log_file_path",
                                                "nothing")           
+            # Search for the test log if there is any
+            l_test_log_files = self.find_test_log(job.remote_log_files)
+            xml_test = src.xmlManager.add_simple_node(xmlj,
+                                                      "test_log_file_path")
+            for test_log_path in l_test_log_files:
+                src.xmlManager.add_simple_node(xml_test, "path", test_log_path)
             
             xmlafter = src.xmlManager.add_simple_node(xmlj, "after", job.after)
             # get the job father
@@ -1513,6 +1548,21 @@ class Gui(object):
                     datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
                
 
+    def find_test_log(self, l_remote_log_files):
+        '''Find if there is a test log (board) in the remote log files and 
+           the path to it. There can be several test command, so the result is
+           a list.
+
+        :param l_remote_log_files List: the list of all remote log files
+        :return: the list of test log files path
+        :rtype: List
+        '''
+        res = []
+        for file_path in l_remote_log_files:
+            dirname = os.path.basename(os.path.dirname(file_path))
+            if dirname == "TEST":
+                res.append(file_path)
+        return res
     
     def last_update(self, finish_status = "finished"):
         '''update information about the jobs for the file xml_file   
@@ -1567,7 +1617,8 @@ def run(args, runner, logger):
             if not options.no_label:
                 logger.write("------ %s\n" % 
                                  src.printcolors.printcHeader(cfg_dir))
-    
+            if not os.path.exists(cfg_dir):
+                continue
             for f in sorted(os.listdir(cfg_dir)):
                 if not f.endswith('.pyconf'):
                     continue
@@ -1652,6 +1703,7 @@ def run(args, runner, logger):
                   today_jobs.ljobs,
                   today_jobs.ljobs_not_today,
                   runner.cfg.VARS.datehour,
+                  logger,
                   file_boards = options.input_boards)
         
         logger.write(src.printcolors.printcSuccess("OK"), 5)
@@ -1707,4 +1759,4 @@ def run(args, runner, logger):
                 today_jobs.gui.last_update()
         # Output the results
         today_jobs.write_all_results()
-        return res
\ No newline at end of file
+        return res