-def update_hat_xml(logDir, application=None):
- xmlHatFilePath = os.path.join(logDir, 'hat.xml')
- if application:
- xmlHat = xmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application})
- else:
- xmlHat = xmlLogFile(xmlHatFilePath, "LOGlist", {"application" : "NO"})
-
- for fileName in os.listdir(logDir):
- sExpr = "^[0-9]{8}_+[0-9]{6}_+.*.xml$"
- oExpr = re.compile(sExpr)
- if oExpr.search(fileName):
- date_hour_cmd = fileName.split('_')
- date_not_formated = date_hour_cmd[0]
- date = "%s/%s/%s" % (date_not_formated[6:8], date_not_formated[4:6], date_not_formated[0:4] )
- hour_not_formated = date_hour_cmd[1]
- hour = "%s:%s:%s" % (hour_not_formated[0:2], hour_not_formated[2:4], hour_not_formated[4:6])
- cmd = date_hour_cmd[2][:-len('.xml')]
-
- xmlHat.add_simple_node("LogCommand", text=fileName, attrib = {"date" : date, "hour" : hour, "cmd" : cmd})
+def append_node_attrib(root_node, attrib):
+ '''Append a new attributes to the node that has node_name as name
+
+ :param root_node etree.Element: the Etree element
+ where to append the new attibutes
+ :param attrib dixt: The attrib to append
+ '''
+ root_node.attrib.update(attrib)
+
+def find_node_by_attrib(xmlroot, name_node, key, value):
+ '''Find the nfirst ode from xmlroot that has name name_node and that has in
+ its attributes {key : value}. Return the node
+
+ :param xmlroot etree.Element: the Etree element where to search
+ :param name_node str: the name of node to search
+ :param key str: the key to search
+ :param value str: the value to search
+ :return: the found node
+ :rtype: xmlroot etree.Element
+ '''
+ l_nodes = xmlroot.findall(name_node)
+ for node in l_nodes:
+ if key not in node.attrib.keys():
+ continue
+ if node.attrib[key] == value:
+ return node
+ return None