def include(self): # Записать эти файлы в storyall.xml try: doc = FromXmlFile("storyall.xml") #Print (doc) dom = doc.documentElement inc = doc.createElement("include") inc.setAttribute("url", self.toFile) isIncAlready=False incs = dom.getElementsByTagName("include") for i in incs: if i.getAttribute("url")==inc.getAttribute("url"): isIncAlready=True break if not isIncAlready: dom.appendChild(inc) dom.appendChild(doc.createTextNode("\n")) f=open("storyall.xml", 'w') Print(doc, f, "utf-8") except Exception, msg: print "Strelka-Canceler::include(): EXCEPTION (while writing to 'storyall.xml'):", msg
def appendStoryallXml(self, xmlFile, templates_path,result_path): os.system("cp "+xmlFile+" "+xmlFile+".old") doc=FromXmlFile(xmlFile) dom=doc.getElementsByTagName("root").item(0) for file in os.listdir(templates_path): if re.search("\.template\.xml",file) and not re.search("impulses\.", file): try: ff = open(result_path+"/"+file.replace(".template",""),'r') ff.close() include = doc.createElement("include") include.setAttribute("url",file.replace(".template","")) includes = dom.getElementsByTagName("include") isAppend = True for inc in includes: if inc.getAttribute("url") == file.replace(".template",""): isAppend = False if isAppend: dom.appendChild(include) newStr=doc.createTextNode("\n") dom.appendChild(newStr) print "В storyall.xml добавлена нода "+str(include) else: print "В storyall.xml уже имеется нода <include url='"+file.replace(".template","")+"' />" except: continue file=open(xmlFile,'w') Print(doc,file,"utf-8") print "Записан файл ", str(xmlFile)
def appendTsXml(self, tsXmlFile): os.system("cp "+tsXmlFile+" "+tsXmlFile+".old") doc=FromXmlFile(tsXmlFile) dom=doc.getElementsByTagName("g").item(0) for file in os.listdir(tsXmlFile.replace("/ts.xml","")): if re.search("impulses\.",file) and re.search("\.xml", file) and not re.search("\.old", file): include = doc.createElement("include") include.setAttribute("url",file) includes = dom.getElementsByTagName("include") isAppend = True for inc in includes: if inc.getAttribute("url") == file: isAppend = False if isAppend: dom.appendChild(include) newStr=doc.createTextNode("\n") dom.appendChild(newStr) #Obj.sig(self.out,_("В ts.xml добавлена нода "+str(include))) print _("В ts.xml добавлена нода "+str(include)) else: #Obj.sig(self.out,_("В ts.xml уже имеется нода <include url='"+file+"' />")) print _("В ts.xml уже имеется нода <include url='"+file+"' />") file=open(tsXmlFile,'w') Print(doc,file,"utf-8") #Obj.sig(self.out,_("Записан файл "+str(tsXmlFile))) print "Записан файл ", str(tsXmlFile)
def saveAll(self): open(self.resultsPath+"/impulses.diag.xml", 'w').write(self.impCont) open(self.resultsPath+"/diag.xml", 'w').write(self.diagCont) diagButtons=open(self.templatePath+"/diag.buttons.xml", 'r').read() open(self.resultsPath+"/diag.buttons.xml", 'w').write(diagButtons) open(self.resultsPath+"/diag-tests.xml", 'w').write(self.umvTestsCont) open(self.resultsPath+"/impulses.diag-tests.xml", 'w').write(self.umvTestsImpCont) self.background() file=open("../svg/diag/"+self.resultsPath+"/full.svg", 'w') Print(self.fullDoc, file, "utf-8") file.close() # Записать эти файлы в storyall.xml try: doc = FromXmlFile(self.resultsPath+"/storyall.xml") Print (doc) dom = doc.documentElement inc = doc.createElement("include") inc.setAttribute("url", "diag-tests.xml") isIncAlready=False incs = dom.getElementsByTagName("include") for i in incs: if i.getAttribute("url")==inc.getAttribute("url"): isIncAlready=True break if not isIncAlready: dom.appendChild(inc) dom.appendChild(doc.createTextNode("\n")) inc = doc.createElement("include") inc.setAttribute("url", "diag.xml") isIncAlready=False incs = dom.getElementsByTagName("include") for i in incs: if i.getAttribute("url")==inc.getAttribute("url"): isIncAlready=True break if not isIncAlready: dom.appendChild(inc) dom.appendChild(doc.createTextNode("\n")) inc = doc.createElement("include") inc.setAttribute("url", "diag.buttons.xml") isIncAlready=False incs = dom.getElementsByTagName("include") for i in incs: if i.getAttribute("url")==inc.getAttribute("url"): isIncAlready=True break if not isIncAlready: dom.appendChild(inc) dom.appendChild(doc.createTextNode("\n")) f=open(self.resultsPath+"/storyall.xml", 'w') Print(doc, f, "utf-8") except Exception, msg: print "Diag::saveAll(): EXCEPTION (while writing to 'storyall.xml'):", msg
class CreatorTU: fileName="" root=None def __init__(self, fileName): self.fileName = fileName print "++++ Начало создания файла '"+fileName+"'" try: f = open(fileName,'r') oldContent = f.read() f.close() f1 = open(fileName+".old",'w') f1.write(oldContent) f1.close() except: donothing=0 file = open(fileName,'w') file.write("<?xml version='1.0' encoding='utf-8'?>\n<root>\n</root>") file.close() self.root=FromXmlFile(fileName) #добавить новый документ для обработки def add(self, doc): #print "$$$$$$$$$$$$$ called add()" objs = doc.getElementsByTagName("obj") for obj in objs: tu = self.root.createElement("tu") klass = obj.getAttribute("class") name = obj.getAttribute("name") sets = obj.getElementsByTagName("sets") for set in sets: tuCommandName = set.getAttribute("attr") if set.firstChild.TEXT_NODE: #print "$$$$$$ ok" tuCommand = set.firstChild.data tuCommand = tuCommand.replace("\"","") tuCommand = tuCommand.replace("'","") tuCommand = tuCommand.replace("(","") tuCommand = tuCommand.replace(")","") tu.setAttribute("class",klass) tu.setAttribute("who",name) tu.setAttribute("prop",tuCommandName) tu.setAttribute("value",tuCommand) newStr = self.root.createTextNode("\n") dom = self.root.getElementsByTagName("root").item(0) dom.appendChild(tu) dom.appendChild(newStr) else: print "ОШИБКА в файле "+str(self.fileName)+" (пропущено) " #деструктор (сохраняет полученный файл) def __del__(self): try: f=open(self.fileName,'w') Print(self.root,f,"utf-8") f.close() print "Сохранен файл '"+self.fileName+"'" except: print "Невозможно сохранить файл '"+self.fileName+"'"
try: doc = FromXmlFile("ts.xml") Print (doc) dom = doc.documentElement inc = doc.createElement("include") inc.setAttribute("url", "impulses.maket.xml") isIncAlready=False incs = dom.getElementsByTagName("include") for i in incs: if i.getAttribute("url")==inc.getAttribute("url"): isIncAlready=True break if not isIncAlready: dom.appendChild(inc) dom.appendChild(doc.createTextNode("\n")) f=open("ts.xml", 'w') Print(doc, f, "utf-8") except Exception, msg: print "Maket::include(): EXCEPTION (while writing to 'ts.xml'):", msg def saveFiles(self): TSseller = seller.TSandTUseller(self.maxImpulses, ".last.ts")