""" some helpfull methods """ import xml.dom.minidom import os.path def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data return rc def changeNodesInIndexMeta(path,node,subnodes,parent=None): """node mit subnodes wird in index.meta in path eingetragen bzw. ausgetauscht""" if os.path.exists(path+"/index.meta"): inFile=file(path+"/index.meta") f=inFile.read() inFile.close() else: f="""""" dom=xml.dom.minidom.parseString(f) root=dom.getElementsByTagName("start")[0] if parent: root=root.getElementsByTagName(parent)[0] # check if node already exist nodeOld=root.getElementsByTagName(node) if nodeOld: # if yes -> delete it root.removeChild(nodeOld[0]).unlink() nodeNew=dom.createElement(node) # create new for subnode in subnodes.keys(): namenode=dom.createElement(subnode) namenodetext=dom.createTextNode(subnodes[subnode]) namenode.appendChild(namenodetext) nodeNew.appendChild(namenode) root.appendChild(nodeNew) writefile=file(path+"/index.meta","w") writefile.write(dom.toxml().encode('utf-8')) writefile.close()