Exemplo n.º 1
0
def setSize(where, height, width):
    print "Установка значений высоты ("+str(height)+") и ширины ("+str(width)+")"
    for file in filesToChange:

	try:
	
	    doc=FromXmlFile(where+"/"+file)
	    doc.getElementsByTagName("svg").item(0).setAttribute("height", str(height))
	    doc.getElementsByTagName("svg").item(0).setAttribute("width", str(width))
	    file1 = open(where+"/"+file,'w')
    	    Print(doc,file1,"utf-8")
	    print "Записан файл "+file
	
	except:
	    donothing=0
	    
	try:
	#if True:
	    doc=FromXmlFile(where+"/"+file)
	    widgets = doc.getElementsByTagName("widget")
	    for widget in widgets:
		if widget.getAttribute("url")=="svg/ladst.svg":
		    widget.setAttribute("height", str(height))
		    widget.setAttribute("width", str(width))
	    	    file1 = open(where+"/"+file,'w')
    		    Print(doc,file1,"utf-8")
		    print "Записан файл "+file
	except:
	    donothing=0
Exemplo n.º 2
0
    def setSize(self):
	print "Установка значений высоты (",str(self.height),") и ширины (",str(self.width),")"
        for file in self.filesToChange:

	    doc=FromXmlFile(self.where+"/"+file)

	    try:
	
		doc.getElementsByTagName("svg").item(0).setAttribute("height", str(self.height))
		doc.getElementsByTagName("svg").item(0).setAttribute("width", str(self.width))
	        file1 = open(self.where+"/"+file,'w')
    		Print(doc,file1,"utf-8")
	
	    except Exception, msg:
		print "SvgSetter::setSize() error: ", msg
	    	    
	    try:
		widgets = doc.getElementsByTagName("widget")
		for widget in widgets:
		    if widget.getAttribute("url")=="svg/ladst.svg":
			widget.setAttribute("height", str(self.height))
			widget.setAttribute("width", str(self.width))
	    		file1 = open(self.where+"/"+file,'w')
    			Print(doc,file1,"utf-8")
	    except Exception, msg:
		print "SvgSetter::setSize() error 2: ", msg
Exemplo n.º 3
0
    def createDOMs(self, fileName):
	doc=FromXmlFile(fileName)
	dom=doc.getElementsByTagName("template").item(0)
	className=doc.getElementsByTagName("template").item(0).getAttribute("class")
	#print "className is '"+className+"' added to classesDOMs={}"
	if className != "":
	    self.classesDOMs[className]=dom
Exemplo n.º 4
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.º 5
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.º 6
0
def load( filename ):
	log = logging.getLogger( "input.planitLoader.load" )

	doc = FromXmlFile( filename )

	rootEL = doc.getElementsByTagName( "project" )[0]

	return loadProject( rootEL )
Exemplo n.º 7
0
def load(filename):
    log = logging.getLogger("input.planitLoader.load")

    doc = FromXmlFile(filename)

    rootEL = doc.getElementsByTagName("project")[0]

    return loadProject(rootEL)
Exemplo n.º 8
0
    def setStationName(self, name, file):
	doc=FromXmlFile(file)
	title = doc.getElementsByTagName("widget").item(0).getAttribute("title")
	#if title == "" or title != "":
	doc.documentElement.setAttribute("title", name)
	f = open (file, 'w')
	Print (doc,f,"utf-8")
	f.close()
	#Obj.sig(self.out,_("Установлено новое имя станции"))
	print _("Установлено новое имя станции")
Exemplo n.º 9
0
    def LoadFromXML(self, filename):
        self.settings = {}
        self.filename = filename
        if USE_MINIDOM:
            doc = minidom.parse(open(filename))
        else:
            doc = FromXmlFile(filename)

        settings = doc.getElementsByTagName("Setting")
        for item in settings:
            if item.attributes:
                myname = ""
                myvalue = ""
                for i in range(0, len(item.attributes)):
                    attr = item.attributes.item(i)
                    if attr.name == "name":
                        myname = attr.value
                    elif attr.name == "value":
                        myvalue = attr.value
                self.settings[myname] = myvalue
Exemplo n.º 10
0
    def __init__(self,resultFileName, path, _isEmptyGroupsRemove=True):
	print "Начало создания таблицы ТС"	
    
	self.resultFileName = resultFileName
	self.path = path
	
	

	# сохранить имеющийся файл resultFileName с расширением old
        try:
            f = open(resultFileName,'r')
            oldContent = f.read()
            f.close()

            f1 = open(resultFileName+".old",'w')
            f1.write(oldContent)
            f1.close()
        except:
            donothing=0


        
	
	#просмотреть данную директорию на наличие файлов impulses.<....>.xml
	try:
	    os.listdir(self.path)
	except:
	    print "\nОШИБКА! Не могу прочитать каталог ", self.path, ". Остановлено\n"
	    return 
	for file in os.listdir(self.path):
	    isRequired=True
	    
	    for nu in self.notUsed:
		if re.search(nu, file):
		    isRequired=False
		    break
	    #if re.search("impulses.",file) and re.search(".xml", file):
	    if isRequired and re.search("^impulses.",file) and re.search(".xml$", file) and not re.search(".old$",file) and not re.search(".back$",file) :
		print "Найден файл "+str(file)
		
		try:
		#if True:
		    impDoc = FromXmlFile(self.path+"/"+file)
		    root = impDoc.getElementsByTagName("root").item(0)
		    objs = root.getElementsByTagName("obj")
		    for obj in objs:
			# имя рассматриваемого объекта
			objName = obj.getAttribute("name")
			RusName = obj.getAttribute("title")
			sets = obj.getElementsByTagName("sets")
			for set in sets:
		    	    if set.firstChild.TEXT_NODE and set.getAttribute("attr")=="address":
		    		ts = set.firstChild.data
				ts = ts.replace("\"","")
				ts = ts.replace("'","")
				ts = re.sub("\s$","", ts,1)
				ts = re.sub("^\s","", ts,1)
			
				#try:
				if True: # '9	 0'
				    tsList = re.split("\s", ts)
				    #получить номера канала, группы и импульса

				    #print objName, " - ", tsList
				    tsList2=[]
				    
				    # удалить пустые члены
				    for tss in tsList:
					if tss!="":
					    tsList2.append(tss)
				    
				    if len(tsList2)!=4:
					print "Объект", objName, "имеет неверный формат ТС"
					sys.exit(0)
				    
				    channel = string.atoi(tsList2[1])
				    group = string.atoi(tsList2[2])
				    imp = string.atoi(tsList2[3])
				    # отправить на обработку объекту класса matrix.Matrix
				    #if(channel==_channel):
				    #    self.matr.append(group,imp, objName)
				    if not (imp==0 or group==0):
					self.channels.append(channel)
					self.groups.append(group)
					self.impulses.append(imp)
					self.names.append(objName)
					if RusName!="":
					    self.RusNames.append(str(RusName.encode("utf-8")))
					else:
					    self.RusNames.append(str(objName))
				#except:
				#    donothing=0
				
		except:
		    print "Не получилось обработать файл "+str(self.path)+"/"+str(file)+" (пропущено)"
		    continue
		    
		    
	channelsReal = []
	#создать копию массива channels
	for i in self.channels:
	    channelsReal.append(i)    
			    
	    
	channelsReal.sort()
	
	self.ch = []
	for i in range(0, len(channelsReal)):
	    if i!=0:
		if channelsReal[i]!=channelsReal[i-1]:
		    self.ch.append(channelsReal[i])
	    else:
		self.ch.append(channelsReal[0])
	
	
	    
	for i in self.ch:
	
	    print "++++++ Канал = "+str(i)
	    
	    matr = matrix.Matrix()
	    
	    for j in range(0, len(self.groups)):
		if self.channels[j]==i:
		    #print str(len(self.names))+" - "+str(len(self.RusNames))
	    	    matr.append(self.groups[j], self.impulses[j], self.names[j], self.RusNames[j])
	    
	    self.matrixes.append( matr.getMatrix(_isEmptyGroupsRemove) )
	    self.XminLines.append( matr.getYmin() )
	    self.YminLines.append( matr.getXmin() )
	    self.Xs.append(matr.getXs())
	    matr = None
Exemplo n.º 11
0
    def LoadFromXML(self, filename):
        self.filename = filename
        self.directory = os.path.split(filename)[0]
        if os.path.exists(os.path.join(self.directory, "settings.xml")):
            self.settings.LoadFromXML(os.path.join(self.directory, "settings.xml"))
        self.content = ContentList()
        self.updatedids = {}
        self.nodes = []
        try: 
            myfile = utils.openFile(filename)
            data = myfile.read()
            myfile.close()
            
            if data.find("\x92") != -1 or data.find("\x93") != -1 or data.find("\x94") != -1:
                data = data.replace("encoding=\"iso8859-1\"", "encoding=\"cp1252\"")
                myfile = utils.openFile(filename, "w")
                myfile.write(data)
                myfile.close()
                print "Ugh, smart quotes..."
                
            if USE_MINIDOM:
                doc = minidom.parse(utils.openFile(filename))
            else:
                doc = FromXmlFile(filename)
        except:
            return "The EClass project file cannot be loaded. The error message is: " + `sys.exc_value.args`

        manifest = doc.getElementsByTagName("manifest")[0]
        if manifest.attributes:
            for i in range(0, len(manifest.attributes)):
                attr = manifest.attributes.item(i)
                if attr.name == "identifier" and string.find(attr.value, self.namespace) != -1:
                    self.id = string.replace(attr.value, self.namespace, "")
                    self.id = string.replace(self.id, "-", "")

            if self.id == "":
                self.id = utils.getUUID()
                    
        metadata = doc.getElementsByTagName("metadata")[0]
        if metadata.childNodes:
            if metadata.getElementsByTagName("PublicationID"):
                if metadata.getElementsByTagName("PublicationID")[0].childNodes:
                    self.pubid = metadata.getElementsByTagName("PublicationID")[0].childNodes[0].nodeValue
                    #print self.pubid
            else:
                self.pubid = ""
            imsmetadata = doc.getElementsByTagName("imsmd:General")
            self._GetMetadata(metadata)
        resources = doc.getElementsByTagName("resource")
        self._GetResources(resources)
        toc = doc.getElementsByTagName("tableofcontents")
        if not toc:
            toc = doc.getElementsByTagName("organization")
            if toc:
                toc = toc[0]
        else:
            toc = toc[0]
        if toc.attributes:
            for i in range(0, len(toc.attributes)):
                attr = toc.attributes.item(i)
                if attr.name == "identifier" and string.find(attr.value, self.namespace) != -1:
                    self.orgid = string.replace(attr.value, self.namespace, "")
                    self.orgid = string.replace(self.orgid, "-", "")

            if self.orgid == "":
                self.orgid = utils.getUUID()
        items = doc.getElementsByTagName("item")[0]
        self._GetNodes(items, None)
        self.CurrentNode = self.nodes[0]
        return ""
        inc_file=str(real_path)+"/"+str(inc_file)
	print "Найден подключаемый файл", inc_file
        
	dom1=None
	try:
	    doc1=FromXmlFile(inc_file)
    	    dom1=doc1.documentElement
	except Exception, msg:
	    print "WARNING: ", msg
	    
	if dom1!=None:        
    	    includedNode=SVGDocument.importNode(dom1,1)
    	    SVGDom.appendChild(includedNode)
        
    
    gs=SVGDocument.getElementsByTagName("g")

    strelki=[]

    paireds=[]

    for g in gs:
	if g.getAttribute("class")=="strelka":
	    strelki.append(g.getAttribute("id"))


    for g in gs:
	if g.getAttribute("class")=="paired":
	    paireds.append(g.getAttribute("id"))

Exemplo n.º 13
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+"'"