10 # Define all possible option for log command : sat log <options>
11 parser = src.options.Options()
12 parser.add_option('t', 'terminal', 'boolean', 'terminal', "Terminal log.")
13 parser.add_option('l', 'last', 'boolean', 'last', "Show the log of the last launched command.")
14 parser.add_option('f', 'full', 'boolean', 'full', "Show the logs of ALL launched commands.")
15 parser.add_option('c', 'clean', 'int', 'clean', "Erase the n most ancient log files.")
18 def show_log_command_in_terminal(filePath, logger):
19 '''Print the contain of filePath. It contains a command log in xml format.
21 :param filePath: The command xml file from which extract the commands context and traces
22 :logger Logger: the logging instance to use in order to print.
24 # Instantiate the readXmlFile class that reads xml files
25 xmlRead = src.xmlManager.readXmlFile(filePath)
26 # Get the attributes containing the context (user, OS, time, etc..)
27 dAttrText = xmlRead.get_attrib('Site')
29 # format dAttrText and print the context
31 for attrib in dAttrText:
32 lAttrText.append((attrib, dAttrText[attrib]))
34 src.print_info(logger, lAttrText)
36 command_traces = xmlRead.get_node_text('Log')
37 # Print it if there is any
39 logger.write(_("Here are the command traces :\n"), 1)
40 logger.write(command_traces, 1)
44 '''Ask for an int n. 0<n<nb
46 :param nb int: The maximum value of the value to be returned by the user.
47 :return: the value entered by the user. Return -1 if it is not as expected
52 rep = raw_input(_("Which one (enter or 0 to quit)? "))
53 # Verify it is on the right range
66 '''method that is called when salomeTools is called with --help option.
68 :return: The text to display for the log command description.
71 return _("Gives access to logs of salomeTools.")
73 def run(args, runner, logger):
74 '''method that is called when salomeTools is called with log parameter.
77 (options, args) = parser.parse_args(args)
79 # get the log directory. If there is an application, it is in cfg.APPLICATION.out_dir, else in user directory
80 logDir = runner.cfg.SITE.log.logDir
82 # If the user asks for a terminal display
84 # Parse the log directory in order to find all the files corresponding to the commands
86 for fileName in os.listdir(logDir):
87 sExpr = "^[0-9]{8}_+[0-9]{6}_+.*.xml$"
88 oExpr = re.compile(sExpr)
89 if oExpr.search(fileName):
90 lLogs.append(fileName)
94 # loop on all files and print it with date, time and command name
96 date_hour_cmd = t.split('_')
97 date_not_formated = date_hour_cmd[0]
98 date = "%s/%s/%s" % (date_not_formated[6:8], date_not_formated[4:6], date_not_formated[0:4] )
99 hour_not_formated = date_hour_cmd[1]
100 hour = "%s:%s:%s" % (hour_not_formated[0:2], hour_not_formated[2:4], hour_not_formated[4:6])
101 cmd = date_hour_cmd[2][:-len('.xml')]
103 num = src.printcolors.printcLabel("%2d" % (nb_logs - index))
104 logger.write("%s: %13s %s %s\n" % (num, cmd, date, hour), 1, False)
107 # ask the user what for what command he wants to be displayed
110 x = ask_value(nb_logs)
112 index = len(lLogs) - int(x)
113 # Show the log corresponding to the selected command call
114 show_log_command_in_terminal(os.path.join(logDir, lLogs[index]), logger)
120 # Find the stylesheets Directory and files
121 xslDir = os.path.join(runner.cfg.VARS.srcDir, 'xsl')
122 xslCommand = os.path.join(xslDir, "command.xsl")
123 xslHat = os.path.join(xslDir, "hat.xsl")
124 imgLogo = os.path.join(xslDir, "LOGO-SAT.png")
126 # copy the stylesheets in the log directory
127 shutil.copy2(xslCommand, logDir)
128 shutil.copy2(xslHat, logDir)
129 shutil.copy2(imgLogo, logDir)
131 # determine the commands to show in the hat log
132 notShownCommands = runner.cfg.INTERNAL.log.notShownCommands
134 notShownCommands = []
136 # Create or update the hat xml that gives access to all the commands log files
137 xmlHatFilePath = os.path.join(logDir, 'hat.xml')
138 src.xmlManager.update_hat_xml(runner.cfg.SITE.log.logDir, application = runner.cfg.VARS.application, notShownCommands = notShownCommands)
140 # open the hat xml in the user editor
141 src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath, logger)