Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
class Diag:

    umvWidth=115
    umvHeight=177
    udoWidth=77
    udoHeight=98

    leftField=3
    rightField=3
    topField=3
    bottomField=3
    
    rioWidth=77
    rioHeight=98

    fullDoc=None

    impTemplate=""
    diagTemplate=""

    rioTemplate=""

    umvTestsTemplate=""
    umvTestsImpTemplate=""
    
    tsSeller=None

    diagCont=""
    impCont=""
    umvTestsCont=""
    umvTestsImpCont=""

    
    resultsPath=""
    iniPath=""
        
    iniStr=""
    
    Y=0 # текущие координаты
    X=0

    includes=[] #список нод <include ...> - вставляться будут свгешки УДО, УМВ, РИО, расставленные в соответствии с конфигом
	


    def __init__(self, templatePath, resultsPath, ini):

	self.tsSeller=seller.TSandTUseller(8, ".last.diag.ts", "1:0")
	self.tsSeller.station=3

	self.templatePath=templatePath
	self.resultsPath=resultsPath
	self.ini = ini
	
	print "Diag::_init__(): Template path=", self.templatePath
	print "Diag::_init__(): Results path=", self.resultsPath
	print "Diag::_init__(): ini =", self.ini

	iniDoc=FromXmlFile(self.ini)
	iniDom=iniDoc.documentElement
    
	self.fullDoc=FromXmlFile(self.templatePath+"/full-template.svg")
	fullDom=iniDoc.documentElement
    
	umvs=iniDom.getElementsByTagName("umv")
	udos=iniDom.getElementsByTagName("udo")
	rios=iniDom.getElementsByTagName("rio")
    
	f1=open(self.templatePath+"/impulses.diag.template.xml")
	self.impTemplate=f1.read()
	f1.close()

	f2=open(self.templatePath+"/diag.template.xml")
	self.diagTemplate=f2.read()
	f2.close()


	f22=open(self.templatePath+"/rio-cps.template.xml")
	self.rioTemplate=f22.read()
	f22.close()


	f3=open(self.templatePath+"/impulses.umv-tests.template.xml")
	self.umvTestsImpTemplate=f3.read()
	f3.close()

	f4=open(self.templatePath+"/umv-tests.template.xml")
	self.umvTestsTemplate=f4.read()
	f4.close()

	self.diagCont+="<?xml version=\"1.0\" encoding='utf-8'?>\n<root>\n"

	self.impCont+="<?xml version=\"1.0\" encoding='utf-8'?>\n<root>\n"

	self.umvTestsCont+="<?xml version=\"1.0\" encoding='utf-8'?>\n<root>\n"
	self.umvTestsImpCont+="<?xml version=\"1.0\" encoding='utf-8'?>\n<root>\n"

	coords = self.makeShelfs(umvs, self.umv, self.umvWidth, self.umvHeight, True, False)

	self.Y += (coords["y"] + 1) * self.umvHeight
	self.X += (coords["x"] + 1) * self.umvWidth

	coords = self.makeShelfs(udos, self.udo, self.udoWidth, self.udoHeight, False, False)

	self.Y += (coords["y"]+1) * self.udoHeight
	if coords["x"]>self.X:
	    self.X += (coords["x"]+1) * self.udoWidth

	coords = self.makeShelfs(rios, self.rio, self.rioWidth, self.rioHeight, False, True)

	self.Y += (coords["y"] + 1) * self.rioHeight
	if coords["x"]>self.X:
	    self.X += (coords["x"] + 1) * self.rioWidth

	self.diagCont+="\n</root>"
	
	self.impCont+="""
<obj class="signalImp" name="test1_button" />
<obj class="signalImp" name="test2_button" />
<obj class="signalImp" name="test3_button" />
<obj class="signalImp" name="test4_button" />
<obj class="signalImp" name="test5_button" />
<obj class="signalImp" name="test6_button" />
<obj class="signalImp" name="test7_button" />
<obj class="signalImp" name="test8_button" />
</root>	"""


	self.umvTestsCont+="\n</root>"
	self.umvTestsImpCont+="\n</root>"








    def getIni(self):
	self.tsSeller.endIni()
	return self.tsSeller.getIni()




    # "сделать полки" shelfArr=список нод, описывающих ту или иную плату  
    # isUMV - это УМВ? Если да - делать тестовые входы
    # shelfWidth, shelfHeight - ширина и высота платы
    def makeShelfs(self, shelfArr, function, shelfWidth, shelfHeight, isUMV=False, isRIO=False ):

	mainX=0
	mainY=0
		
        #создание полок с платами
        for shelf in shelfArr:
	    include=self.fullDoc.createElement("include")
	    
	    xStr=shelf.getAttribute("x")
	    x=string.atoi(xStr)
	    
	    yStr=shelf.getAttribute("y")
	    y=string.atoi(yStr)

	    name=shelf.getAttribute("name")
	    title=shelf.getAttribute("title")
		    	    
	    include.setAttribute("url", "svg/diag/"+name+".svg")
	    include.setAttribute("x", str(self.leftField + x*shelfWidth))
	    include.setAttribute("y", str(self.Y + self.topField + y*shelfHeight))

	    if x > mainX: mainX=x
	    if y > mainY: mainY=y	    
	    
	    self.includes.append(include)
	    function(name,title)
	    
	    tmp = ""
	    
	    if not isRIO:
		tmp=re.sub("@NAME@", str(name), self.diagTemplate, 100)
		tmp=re.sub("@TITLE@", str(title.encode("utf-8")), tmp, 100)	    
	    else:
		tmp=re.sub("@NAME@", str(name), self.rioTemplate, 100)
		tmp=re.sub("@TITLE@", str(title.encode("utf-8")), tmp, 100)	    

	    
	    
	    self.diagCont+=tmp

	    tmp=re.sub("@NAME@", str(name), self.impTemplate, 100)
	    tmp=re.sub("@TITLE@", str(title.encode("utf-8")), tmp, 100)	    
	    
	    i=0
	    while True:
		if re.search("@TS@", tmp) != None:
		    tmp = re.sub("@TS@", self.tsSeller.buy(self.tsSeller.getFullTitle(i,tmp)), tmp, 1 )
		    i+=1
		else:
		    break
											    
	    self.impCont+=tmp
	    

	    tmp=re.sub("@NAME@", str(name)+"@NAME@", self.umvTestsTemplate, 100)
	    tmp=re.sub("@TITLE_R@", str(title.encode("utf-8")+"р")+"@TITLE@", tmp, 100)

	    tmpImp=re.sub("@NAME@", str(name)+"@NAME@", self.umvTestsImpTemplate, 100)
	    tmpImp=re.sub("@TITLE_R@", str(title.encode("utf-8")+"р")+"@TITLE@", tmpImp, 100)

	    tmp=re.sub("@TITLE_O@", str(title.encode("utf-8")+"о")+"@TITLE@", tmp, 100)
	    tmpImp=re.sub("@TITLE_O@", str(title.encode("utf-8")+"о")+"@TITLE@", tmpImp, 100)

	    
	    if isUMV:
    	        for i in range(1,9):
		    
	    	    tmp1=re.sub("@NAME@", "w"+str(i), tmp, 100)
		    tmp1=re.sub("@TITLE@", ".Тест. вх. "+str(i)+"", tmp1, 100)
		    self.umvTestsCont+=tmp1
		    tmp2=re.sub("@NAME@", "w"+str(i), tmpImp, 100)
		    tmp2=re.sub("@TITLE@", ". Тест. вх. "+str(i)+"", tmp2, 100)
		    i=0
		    while True:
	    	        if re.search("@TS@", tmp2) != None:
		    	    tmp2 = re.sub("@TS@", self.tsSeller.buy(self.tsSeller.getFullTitle(i,tmp2)), tmp2, 1 )
			    i+=1
		        else:
			    break
		    self.umvTestsImpCont+=tmp2






	coords={}
	coords["x"]=mainX
	coords["y"]=mainY
	
	#print "makeShelfs: returned mainX="+str(mainX)+", mainY="+str(mainY)
	return coords


	

	







    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





	# Записать эти файлы в ts.xml
	try:
	    doc = FromXmlFile(self.resultsPath+"/ts.xml")
	    Print (doc)
	    dom = doc.documentElement
	    
	    inc = doc.createElement("include")
	    inc.setAttribute("url", "impulses.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", "impulses.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"))
	    	
		
	    f=open(self.resultsPath+"/ts.xml", 'w')
	    Print(doc, f, "utf-8")
	
	except Exception, msg:
	    print "Diag::saveAll(): EXCEPTION (while writing to 'ts.xml'):", msg
Exemplo n.º 6
0
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+"'"
Exemplo n.º 7
0
	    Print(doc, f, "utf-8")

	except Exception, msg:
	    print "Maket::include(): EXCEPTION (while writing to 'storyall.xml'):", msg





	# Записать эти файлы в ts.xml
	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: