+ # get the log directory.
+ logDir = src.get_log_path(runner.cfg)
+
+ # Print a header
+ nb_files_log_dir = len(glob.glob(os.path.join(logDir, "*")))
+ info = [("log directory", logDir),
+ ("number of log files", nb_files_log_dir)]
+ src.print_info(logger, info)
+
+ # If the clean options is invoked,
+ # do nothing but deleting the concerned files.
+ if options.clean:
+ nbClean = options.clean
+ # get the list of files to remove
+ lLogs = src.logger.list_log_file(logDir,
+ src.logger.log_all_command_file_expression)
+ nbLogFiles = len(lLogs)
+ # Delete all if the invoked number is bigger than the number of log files
+ if nbClean > nbLogFiles:
+ nbClean = nbLogFiles
+ # Get the list to delete and do the removing
+ lLogsToDelete = sorted(lLogs)[:nbClean]
+ for filePath, __, __, __, __, __, __ in lLogsToDelete:
+ # remove the xml log file
+ remove_log_file(filePath, logger)
+ # remove also the corresponding txt file in OUT directory
+ txtFilePath = os.path.join(os.path.dirname(filePath),
+ 'OUT',
+ os.path.basename(filePath)[:-len('.xml')] + '.txt')
+ remove_log_file(txtFilePath, logger)
+ # remove also the corresponding pyconf (do not exist 2016-06)
+ # file in OUT directory
+ pyconfFilePath = os.path.join(os.path.dirname(filePath),
+ 'OUT',
+ os.path.basename(filePath)[:-len('.xml')] + '.pyconf')
+ remove_log_file(pyconfFilePath, logger)
+
+
+ logger.write(src.printcolors.printcSuccess("OK\n"))
+ logger.write("%i logs deleted.\n" % nbClean)
+ return 0
+
+ # determine the commands to show in the hat log
+ notShownCommands = list(runner.cfg.INTERNAL.log.not_shown_commands)
+ if options.full:
+ notShownCommands = []
+
+ # Find the stylesheets Directory and files
+ xslDir = os.path.join(runner.cfg.VARS.srcDir, 'xsl')
+ xslCommand = os.path.join(xslDir, "command.xsl")
+ xslHat = os.path.join(xslDir, "hat.xsl")
+ xsltest = os.path.join(xslDir, "test.xsl")
+ imgLogo = os.path.join(xslDir, "LOGO-SAT.png")
+
+ # copy the stylesheets in the log directory
+ # OP We use copy instead of copy2 to update the creation date
+ # So we can clean the LOGS directories easily
+ try:
+ src.ensure_path_exists(logDir)
+ shutil.copy(xslCommand, logDir)
+ shutil.copy(xslHat, logDir)
+ src.ensure_path_exists(os.path.join(logDir, "TEST"))
+ shutil.copy(xsltest, os.path.join(logDir, "TEST"))
+ shutil.copy(imgLogo, logDir)
+ except:
+ # we are here if an user make sat log in jenkins LOGS without write rights
+ # Make a warning and do nothing
+ logger.warning("problem for writing in directory '%s', may be not owner." % logDir)
+
+ # If the last option is invoked, just, show the last log file
+ if options.last_compile:
+ src.check_config_has_application(runner.cfg)
+ log_dirs = os.listdir(os.path.join(runner.cfg.APPLICATION.workdir, 'LOGS'))
+ show_last_logs(logger, runner.cfg, log_dirs)
+ return 0
+
+ # If the last option is invoked, just, show the last log file
+ if options.last:
+ lastLogFilePath = get_last_log_file(logDir,
+ notShownCommands + ["config"])
+ if options.terminal:
+ # Show the log corresponding to the selected command call
+ print_log_command_in_terminal(lastLogFilePath, logger)
+ else:
+ # open the log xml file in the user editor
+ src.system.show_in_editor(runner.cfg.USER.browser,
+ lastLogFilePath, logger)
+ return 0