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.")
14 def show_log_command_in_terminal(filePath, logger):
15 '''Print the contain of filePath. It contains a command log in xml format.
17 :param filePath: The command xml file from which extract the commands context and traces
18 :logger Logger: the logging instance to use in order to print.
20 # Instantiate the readXmlFile class that reads xml files
21 xmlRead = src.xmlManager.readXmlFile(filePath)
22 # Get the attributes containing the context (user, OS, time, etc..)
23 dAttrText = xmlRead.get_attrib('Site')
25 # format dAttrText and print the context
27 for attrib in dAttrText:
28 lAttrText.append((attrib, dAttrText[attrib]))
30 src.print_info(logger, lAttrText)
32 command_traces = xmlRead.get_node_text('Log')
33 # Print it if there is any
35 logger.write(_("Here are the command traces :\n"), 1)
36 logger.write(command_traces, 1)
40 '''Ask for an int n. 0<n<nb
42 :param nb int: The maximum value of the value to be returned by the user.
43 :return: the value entered by the user. Return -1 if it is not as expected
48 rep = raw_input(_("Which one (enter or 0 to quit)? "))
49 # Verify it is on the right range
62 '''method that is called when salomeTools is called with --help option.
64 :return: The text to display for the log command description.
67 return _("Gives access to logs of salomeTools.")
69 def run(args, runner, logger):
70 '''method that is called when salomeTools is called with log parameter.
73 (options, args) = parser.parse_args(args)
75 # get the log directory. If there is an application, it is in cfg.APPLICATION.out_dir, else in user directory
76 logDir = runner.cfg.SITE.log.logDir
78 # If the user asks for a terminal display
80 # Parse the log directory in order to find all the files corresponding to the commands
82 for fileName in os.listdir(logDir):
83 sExpr = "^[0-9]{8}_+[0-9]{6}_+.*.xml$"
84 oExpr = re.compile(sExpr)
85 if oExpr.search(fileName):
86 lLogs.append(fileName)
90 # loop on all files and print it with date, time and command name
92 date_hour_cmd = t.split('_')
93 date_not_formated = date_hour_cmd[0]
94 date = "%s/%s/%s" % (date_not_formated[6:8], date_not_formated[4:6], date_not_formated[0:4] )
95 hour_not_formated = date_hour_cmd[1]
96 hour = "%s:%s:%s" % (hour_not_formated[0:2], hour_not_formated[2:4], hour_not_formated[4:6])
97 cmd = date_hour_cmd[2][:-len('.xml')]
99 num = src.printcolors.printcLabel("%2d" % (nb_logs - index))
100 logger.write("%s: %13s %s %s\n" % (num, cmd, date, hour), 1, False)
103 # ask the user what for what command he wants to be displayed
106 x = ask_value(nb_logs)
108 index = len(lLogs) - int(x)
109 # Show the log corresponding to the selected command call
110 show_log_command_in_terminal(os.path.join(logDir, lLogs[index]), logger)
116 # Find the stylesheets Directory and files
117 xslDir = os.path.join(runner.cfg.VARS.srcDir, 'xsl')
118 xslCommand = os.path.join(xslDir, "command.xsl")
119 xslHat = os.path.join(xslDir, "hat.xsl")
120 imgLogo = os.path.join(xslDir, "LOGO-SAT.png")
122 # copy the stylesheets in the log directory
123 shutil.copy2(xslCommand, logDir)
124 shutil.copy2(xslHat, logDir)
125 shutil.copy2(imgLogo, logDir)
127 # Create or update the hat xml that gives access to all the commands log files
128 xmlHatFilePath = os.path.join(logDir, 'hat.xml')
129 src.xmlManager.update_hat_xml(runner.cfg.SITE.log.logDir, runner.cfg.VARS.application)
131 # open the hat xml in the user editor
132 src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath, logger)