]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
compatibility python 2.6 and bug fix in sat log -t
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Fri, 12 Feb 2016 12:57:07 +0000 (13:57 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Fri, 12 Feb 2016 12:57:07 +0000 (13:57 +0100)
commands/log.py
src/logger.py
src/system.py
src/xmlManager.py
test/_testTools/tools.py

index 3192a2f71c4478f3ae4bd7944b48d667809a0995..b02d48891e21cc2d15b2a4ec804dae0d9085a10c 100644 (file)
@@ -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
index cfa78ffd4e79495da2b30e21db7cdbbb416cdf4d..6568e57d37e8713586850ba8360c8f599477bc0d 100644 (file)
@@ -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
index cc8a39fa84351d16ac91f0e7006787e81bcaf6e9..c595a43527481838b9a1e30ff761d4e6e00f417c 100644 (file)
 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
index 5483c7048188e929bdf9882564506421d52730c7..609f43d6dcb439b94cf4303b15ab13d952dab922 100644 (file)
@@ -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
index 6d13ac20339d8cd59e1872d6dd5d56b134138d7c..61de6cfdc9ca1c08380f08a686b02100dcf1d085 100644 (file)
@@ -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: