X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=commands%2Fjobs.py;h=2b29f3aa11c5a5cb2702ce8fbbde21cfa3c6deb6;hb=e78f0659aceb8e693fd02b01531215180256543c;hp=6fd6cedbb60985f9a0389639256f879b816cb689;hpb=8a1c8058dd8d5010d3b875bcdeb5562397fc9e5a;p=tools%2Fsat.git diff --git a/commands/jobs.py b/commands/jobs.py index 6fd6ced..2b29f3a 100644 --- a/commands/jobs.py +++ b/commands/jobs.py @@ -22,6 +22,7 @@ import time import csv import shutil import itertools +import re import paramiko import src @@ -35,7 +36,7 @@ CSV_DELIMITER = ";" parser = src.options.Options() parser.add_option('n', 'name', 'string', 'jobs_cfg', - _('The name of the config file that contains' + _('Mandatory: The name of the config file that contains' ' the jobs configuration')) parser.add_option('o', 'only_jobs', 'list2', 'only_jobs', _('Optional: the list of jobs to launch, by their name. ')) @@ -52,7 +53,7 @@ parser.add_option('p', 'publish', 'boolean', 'publish', parser.add_option('i', 'input_boards', 'string', 'input_boards', _("Optional: " "the path to csv file that contain " "the expected boards."),"") -parser.add_option('n', 'completion', 'boolean', 'no_label', +parser.add_option('', 'completion', 'boolean', 'no_label', _("Optional (internal use): do not print labels, Works only " "with --list."), False) @@ -441,6 +442,8 @@ class Job(object): """In case of a failing job, one has to cancel every job that depend on it. This method put the job as failed and will not be executed. """ + if self.cancelled: + return self._has_begun = True self._has_finished = True self.cancelled = True @@ -798,8 +801,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) @@ -1024,7 +1027,7 @@ class Gui(object): see the jobs states ''' - def __init__(self, xml_dir_path, l_jobs, l_jobs_not_today, file_boards=""): + def __init__(self, xml_dir_path, l_jobs, l_jobs_not_today, prefix, file_boards=""): '''Initialization :param xml_dir_path str: The path to the directory where to put @@ -1034,6 +1037,9 @@ class Gui(object): :param file_boards str: the file path from which to read the expected boards ''' + # The prefix to add to the xml files : date_hour + self.prefix = prefix + # The path of the csv files to read to fill the expected boards self.file_boards = file_boards @@ -1046,12 +1052,20 @@ 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") + + # Find history for each job + self.history = {} + self.find_history(l_jobs, l_jobs_not_today) + # The xml files that corresponds to the boards. # {name_board : xml_object}} self.d_xml_board_files = {} + # Create the lines and columns self.initialize_boards(l_jobs, l_jobs_not_today) @@ -1059,6 +1073,9 @@ class Gui(object): 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, @@ -1170,10 +1187,28 @@ class Gui(object): # that will not be launched today self.put_jobs_not_today(l_jobs_not_today, xml_jobs) + # add also the infos node xml_file.add_simple_node("infos", attrib={"name" : "last update", "JobsCommandStatus" : "running"}) - + + # and put the history node + history_node = xml_file.add_simple_node("history") + name_board = os.path.basename(xml_file.logFile)[:-len(".xml")] + # serach for board files + expression = "^[0-9]{8}_+[0-9]{6}_" + name_board + ".xml$" + oExpr = re.compile(expression) + # Get the list of xml borad files that are in the log directory + for file_name in os.listdir(self.xml_dir_path): + if oExpr.search(file_name): + date = os.path.basename(file_name).split("_")[0] + file_path = os.path.join(self.xml_dir_path, file_name) + src.xmlManager.add_simple_node(history_node, + "link", + text=file_path, + attrib={"date" : date}) + + # Find in each board the squares that needs to be filled regarding the # input csv files but that are not covered by a today job for board in self.d_input_boards.keys(): @@ -1192,7 +1227,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 @@ -1218,6 +1292,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 @@ -1312,6 +1393,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) @@ -1391,19 +1480,32 @@ class Gui(object): attrib={"JobsCommandStatus" : finish_status}) # Write the file self.write_xml_files() - + + def write_xml_file(self, xml_file, stylesheet): + ''' Write one xml file and the same file with prefix + ''' + xml_file.write_tree(stylesheet) + file_path = xml_file.logFile + file_dir = os.path.dirname(file_path) + file_name = os.path.basename(file_path) + file_name_with_prefix = self.prefix + "_" + file_name + xml_file.write_tree(stylesheet, os.path.join(file_dir, + file_name_with_prefix)) + def write_xml_files(self): ''' Write the xml files ''' - self.xml_global_file.write_tree(STYLESHEET_GLOBAL) + self.write_xml_file(self.xml_global_file, STYLESHEET_GLOBAL) for xml_file in self.d_xml_board_files.values(): - xml_file.write_tree(STYLESHEET_BOARD) - + self.write_xml_file(xml_file, STYLESHEET_BOARD) + + ## # Describes the command def description(): return _("The jobs command launches maintenances that are described" - " in the dedicated jobs configuration file.") + " in the dedicated jobs configuration file.\n\nexample:\nsat " + "jobs --name my_jobs --publish") ## # Runs the command. @@ -1495,6 +1597,7 @@ def run(args, runner, logger): gui = Gui(runner.cfg.USER.log_dir, today_jobs.ljobs, today_jobs.ljobs_not_today, + runner.cfg.VARS.datehour, file_boards = options.input_boards) # Display the list of the xml files