+parser.add_option('t', 'terminal', 'boolean', 'terminal', "Optional: "
+ "Terminal log.")
+parser.add_option('l', 'last', 'boolean', 'last', "Show the log of the last "
+ "Optional: launched command.")
+parser.add_option('', 'last_terminal', 'boolean', 'last_terminal', "Show the "
+ "log of the last compilations"
+ "Optional: launched command.")
+parser.add_option('f', 'full', 'boolean', 'full', "Optional: Show the logs of "
+ "ALL the launched commands.")
+parser.add_option('c', 'clean', 'int', 'clean', "Optional: Erase the n most "
+ "ancient log files.")
+parser.add_option('n', 'no_browser', 'boolean', 'no_browser', "Optional: Do not"
+ " launch the browser at the end of the command. Only update "
+ "the hat file.")
+
+def get_last_log_file(logDir, notShownCommands):
+ '''Used in case of last option. Get the last log command file path.
+
+ :param logDir str: The directory where to search the log files
+ :param notShownCommands list: the list of commands to ignore
+ :return: the path to the last log file
+ :rtype: str
+ '''
+ last = (_, 0)
+ for fileName in os.listdir(logDir):
+ # YYYYMMDD_HHMMSS_namecmd.xml
+ sExpr = src.logger.log_macro_command_file_expression
+ oExpr = re.compile(sExpr)
+ if oExpr.search(fileName):
+ # get date and hour and format it
+ date_hour_cmd = fileName.split('_')
+ datehour = date_hour_cmd[0] + date_hour_cmd[1]
+ cmd = date_hour_cmd[2]
+ if cmd in notShownCommands:
+ continue
+ if int(datehour) > last[1]:
+ last = (fileName, int(datehour))
+ return os.path.join(logDir, last[0])
+
+def remove_log_file(filePath, logger):
+ '''if it exists, print a warning and remove the input file
+
+ :param filePath: the path of the file to delete
+ :param logger Logger: the logger instance to use for the print
+ '''
+ if os.path.exists(filePath):
+ logger.write(src.printcolors.printcWarning("Removing ")
+ + filePath + "\n", 5)
+ os.remove(filePath)
+
+def print_log_command_in_terminal(filePath, logger):
+ '''Print the contain of filePath. It contains a command log in xml format.
+
+ :param filePath: The command xml file from which extract the commands
+ context and traces
+ :param logger Logger: the logging instance to use in order to print.
+ '''
+ logger.write(_("Reading ") + src.printcolors.printcHeader(filePath) + "\n", 5)
+ # Instantiate the ReadXmlFile class that reads xml files
+ xmlRead = src.xmlManager.ReadXmlFile(filePath)
+ # Get the attributes containing the context (user, OS, time, etc..)
+ dAttrText = xmlRead.get_attrib('Site')
+ # format dAttrText and print the context
+ lAttrText = []
+ for attrib in dAttrText:
+ lAttrText.append((attrib, dAttrText[attrib]))
+ logger.write("\n", 1)
+ src.print_info(logger, lAttrText)
+ # Get the traces
+ command_traces = xmlRead.get_node_text('Log')
+ # Print it if there is any
+ if command_traces:
+ logger.write(src.printcolors.printcHeader(
+ _("Here are the command traces :\n")), 1)
+ logger.write(command_traces, 1)
+ logger.write("\n", 1)
+
+def show_last_logs(logger, config, log_dirs):
+ """Show last compilation logs"""
+ log_dir = os.path.join(config.APPLICATION.workdir, 'LOGS')
+ # list the logs
+ nb = len(log_dirs)
+ nb_cols = 4
+ col_size = (nb / nb_cols) + 1
+ for index in range(0, col_size):
+ for i in range(0, nb_cols):
+ k = index + i * col_size
+ if k < nb:
+ l = log_dirs[k]
+ str_indice = src.printcolors.printcLabel("%2d" % (k+1))
+ log_name = l
+ logger.write("%s: %-30s" % (str_indice, log_name), 1, False)
+ logger.write("\n", 1, False)
+
+ # loop till exit
+ x = -1
+ while (x < 0):
+ x = ask_value(nb)
+ if x > 0:
+ product_log_dir = os.path.join(log_dir, log_dirs[x-1])
+ show_product_last_logs(logger, config, product_log_dir)