From: Serge Rehbinder Date: Fri, 12 Feb 2016 12:57:07 +0000 (+0100) Subject: compatibility python 2.6 and bug fix in sat log -t X-Git-Tag: sprint-02~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=944d96158c2cf37fc7b9ad83cd3da73b23fbf221;p=tools%2Fsat.git compatibility python 2.6 and bug fix in sat log -t --- diff --git a/commands/log.py b/commands/log.py index 3192a2f..b02d488 100644 --- a/commands/log.py +++ b/commands/log.py @@ -20,12 +20,16 @@ def show_log_command_in_terminal(filePath, logger): # Instantiate the readXmlFile class that reads xml files xmlRead = src.xmlManager.readXmlFile(filePath) # Get the attributes containing the context (user, OS, time, etc..) - lAttrText = xmlRead.get_attrib_text('name') + 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) - # Print the context src.print_info(logger, lAttrText) # Get the traces - command_traces = xmlRead.get_node_text('traces') + command_traces = xmlRead.get_node_text('Log') # Print it if there is any if command_traces: logger.write(_("Here are the command traces :\n"), 1) @@ -128,4 +132,4 @@ def run(args, runner, logger): src.xmlManager.update_hat_xml(runner.cfg.VARS.logDir) # open the hat xml in the user editor - src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath) \ No newline at end of file + src.system.show_in_editor(runner.cfg.USER.browser, xmlHatFilePath, logger) \ No newline at end of file diff --git a/src/logger.py b/src/logger.py index cfa78ff..6568e57 100644 --- a/src/logger.py +++ b/src/logger.py @@ -133,7 +133,7 @@ class Logger(object): t0 = datetime.datetime(int(Y), int(m), int(dd), int(H), int(M), int(S)) tf = dt delta = tf - t0 - total_time = delta.total_seconds() + total_time = timedelta_total_seconds(delta) hours = int(total_time / 3600) minutes = int((total_time - hours*3600) / 60) seconds = total_time - hours*3600 - minutes*60 @@ -164,4 +164,15 @@ def date_to_datetime(date): H = date[9:11] M = date[11:13] S = date[13:15] - return Y, m, dd, H, M, S \ No newline at end of file + return Y, m, dd, H, M, S + +def timedelta_total_seconds(timedelta): + '''Little method to replace total_seconds from datetime module in order to be compatible with old python versions + + :param timedelta datetime.timedelta: The delta between two dates + :return: The number of seconds corresponding to timedelta. + :rtype: float + ''' + return ( + timedelta.microseconds + 0.0 + + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6 \ No newline at end of file diff --git a/src/system.py b/src/system.py index cc8a39f..c595a43 100644 --- a/src/system.py +++ b/src/system.py @@ -20,11 +20,11 @@ In this file : all functions that do a system call, like open a browser or an editor, or call a git command ''' -import sys import subprocess +from . import printcolors -def show_in_editor(editor, filePath): +def show_in_editor(editor, filePath, logger): '''open filePath using editor. :param editor str: The editor to use. @@ -40,8 +40,9 @@ def show_in_editor(editor, filePath): try: # launch cmd using subprocess.Popen cmd = editor % filePath + logger.write('Launched command:\n' + cmd + '\n', 5) p = subprocess.Popen(cmd, shell=True) p.communicate() except: - sys.stderr.write("Unable to edit file %s\n" % filePath) + logger.write(printcolors.printcError(_("Unable to edit file %s\n") % filePath), 1) \ No newline at end of file diff --git a/src/xmlManager.py b/src/xmlManager.py index 5483c70..609f43d 100644 --- a/src/xmlManager.py +++ b/src/xmlManager.py @@ -94,15 +94,10 @@ class readXmlFile(object): etree_inst = etree.parse(filePath) self.xmlroot = etree_inst.parse(filePath) - def get_attrib_text(self, attribname): + def get_attrib(self, node_name): '''Parse the root nodes and get all node that have the attribname. Return the list of [(value of attribname, text), ...] ''' - lres = [] - # Loop on all root nodes - for field in self.xmlroot: - if attribname in field.attrib: - lres.append((field.attrib[attribname], field.text)) - return lres + return self.xmlroot.find(node_name).attrib def get_node_text(self, node): '''Get the text of the first node that has name that corresponds to the parameter node diff --git a/test/_testTools/tools.py b/test/_testTools/tools.py index 6d13ac2..61de6cf 100644 --- a/test/_testTools/tools.py +++ b/test/_testTools/tools.py @@ -53,7 +53,7 @@ def kill9(pid): def check_proc_existence_and_kill(regex): cmd = 'ps aux | grep "' + regex + '"' - psRes = subprocess.check_output(cmd, shell=True) + psRes = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] psRes = psRes.split('\n') for line in psRes: if 'grep' in line or len(line) == 0: