# 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)
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
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
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
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.
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
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
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: