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.")
15 '''Ask for an int n. 0<n<nb
17 :param nb int: The maximum value of the value to be returned by the user.
18 :return: the value entered by the user. Return -1 if it is not as expected
23 rep = raw_input(_("Which one (enter or 0 to quit)? "))
24 # Verify it is on the right range
36 def show_log_command_in_terminal(filePath, logger):
37 '''Print the contain of filePath. It contains a command log in xml format.
39 :param filePath: The command xml file from which extract the commands context and traces
40 :logger Logger: the logging instance to use in order to print.
42 # Instantiate the readXmlFile class that reads xml files
43 xmlRead = src.xmlManager.readXmlFile(filePath)
44 # Get the attributes containing the context (user, OS, time, etc..)
45 lAttrText = xmlRead.get_attrib_text('name')
48 src.print_info(logger, lAttrText)
50 command_traces = xmlRead.get_node_text('traces')
51 # Print it if there is any
53 logger.write(_("Here are the command traces :\n"), 1)
54 logger.write(command_traces, 1)
58 '''method that is called when salomeTools is called with --help option.
60 :return: The text to display for the log command description.
63 return _("Gives access to logs of salomeTools.")
65 def run(args, runner, logger):
66 '''method that is called when salomeTools is called with log parameter.
69 (options, args) = parser.parse_args(args)
71 # get the log directory. If there is an application, it is in cfg.APPLICATION.out_dir, else in user directory
72 logDir = runner.cfg.VARS.logDir
74 # If the user asks for a terminal display
76 # Parse the log directory in order to find all the files corresponding to the commands
78 for fileName in os.listdir(logDir):
79 sExpr = "^[0-9]{8}_+[0-9]{6}_+.*.xml$"
80 oExpr = re.compile(sExpr)
81 if oExpr.search(fileName):
82 lLogs.append(fileName)
86 # loop on all files and print it with date, time and command name
88 date_hour_cmd = t.split('_')
89 date_not_formated = date_hour_cmd[0]
90 date = "%s/%s/%s" % (date_not_formated[6:8], date_not_formated[4:6], date_not_formated[0:4] )
91 hour_not_formated = date_hour_cmd[1]
92 hour = "%s:%s:%s" % (hour_not_formated[0:2], hour_not_formated[2:4], hour_not_formated[4:6])
93 cmd = date_hour_cmd[2][:-len('.xml')]
95 num = src.printcolors.printcLabel("%2d" % (nb_logs - index))
96 logger.write("%s: %13s %s %s\n" % (num, cmd, date, hour), 1, False)
99 # ask the user what for what command he wants to be displayed
102 x = ask_value(nb_logs)
104 index = len(lLogs) - int(x)
105 # Show the log corresponding to the selected command call
106 show_log_command_in_terminal(os.path.join(logDir, lLogs[index]), logger)
112 # Find the stylesheets Directory and files
113 xslDir = os.path.join(runner.cfg.VARS.srcDir, 'xsl')
114 xslCommand = os.path.join(xslDir, "command.xsl")
115 xslHat = os.path.join(xslDir, "hat.xsl")
116 imgLogo = os.path.join(xslDir, "LOGO-SAT.png")
118 # copy the stylesheets in the log directory
119 shutil.copy2(xslCommand, logDir)
120 shutil.copy2(xslHat, logDir)
121 shutil.copy2(imgLogo, logDir)
123 # Create or update the hat xml that gives access to all the commands log files
124 xmlHatFilePath = os.path.join(logDir, 'hat.xml')
125 if 'APPLICATION' in runner.cfg:
126 src.xmlManager.update_hat_xml(runner.cfg.VARS.logDir, runner.cfg.VARS.application)
128 src.xmlManager.update_hat_xml(runner.cfg.VARS.logDir)
130 # open the hat xml in the user editor
131 src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath)