Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, xml.dom.minidom
- class general:
- def __init__(self,code=0):
- self.setCode(code)
- def setCode(self,value): self.__code=value
- def getCode(self):return self.__code
- class generallist :
- def __init__(self):self.__list = []
- def clear(self): self.__list = []
- def findByCode(self,code):
- for l in self.__list:
- return l
- break
- def getCodes(self) : return [s.getCode() for s in self.__list]
- def appendList (self,value):self.__list.append(value)
- def removeList(self,code):
- for s in self.__list:
- if s.getCode()==code:self.__list.remove(s)
- class generallistEdit(generallist):
- def getNewCode(self):
- m=0
- for c in self.getCodes():
- if c>m:m=c
- return m+1
- def setName(self,code,value):return self.findByCode(code).setName(value)
- class Vidstanka(general):
- def __init__(self,country='',year=0,mark='',code=0):
- self.setCountry(country)
- self.setYear(year)
- self.setMark(mark)
- self.setCode(code)
- def setCountry(self,value):self.__country=value
- def setYear(self,value):self.__year=value
- def setMark(self,value):self.__mark=value
- def setCode(self,value):self.__code=value
- def getCountry(self):return self.__country
- def getYear(self):return self.__year
- def getMark(self):return self.__mark
- def getCode(self):return self.__code
- class VidstankalistEdit(generallistEdit):
- def newRec (self,country='',year=0,mark='',code=0):
- self.appendList(Vidstanka(country,year,mark,code))
- def setCountry(self,code,value):self.findByCode(code).setCountry(value)
- def setYear(self,code,value):self.findByCode(code).setYear(value)
- def setMark(self,code,value):self.findByCode(code).setMark(value)
- def getCountry(self,code):return self.findByCode(code).getCountry()
- def getYear(self,code):return self.findByCode(code).getYear()
- def getMark(self,code):return self.findByCode(code).getMark()
- class Vidremonta(general):
- def __init__(self,name='',time=0,cost=0,special='',code=0):
- self.setName(name)
- self.setTime(time)
- self.setCost(cost)
- self.setSpecial(special)
- self.setCode(code)
- def setName(self,value):self.__name=value
- def setTime(self,value):self.__time=value
- def setCost(self,value):self.__cost=value
- def setSpecial(self,value):self.__special=value
- def setCode(self,value):self.__code=value
- def getName(self):return self.__name
- def getTime(self):return self.__time
- def getCost(self):return self.__cost
- def getSpecial(self):return self.__special
- def getCode(self):return self.__code
- class VidremontalistEdit(generallistEdit):
- def newRec (self,name='',time=0,cost=0,special='',code=0):
- self.appendList(Vidremonta(name,time,cost,special,code))
- def setName(self,code,value):self.findByCode(code).setName(value)
- def setTime(self,code,value):self.findByCode(code).setTime(value)
- def setCost(self,code,value):self.findByCode(code).setCost(value)
- def setSpecial(self,code,value):self.findByCode(code).setSpecial(value)
- def getName(self,code):return self.findByCode(code).getName()
- def getTime(self,code):return self.findByCode(code).getTime()
- def getCost(self,code):return self.findByCode(code).getCost()
- def getSpecial(self,code):return self.findByCode(code).getSpecial()
- class Remont(general):
- def __init__(self,vidstanka='',data='',vidremonta='',speciall='',code=0):
- self.setVidstanka(vidstanka)
- self.setData(data)
- self.setVidremonta(vidremonta)
- self.setSpeciall(speciall)
- self.setCode(code)
- def setVidstanka(self,value):self.__vidstanka=value
- def setData(self,value):self.__data=value
- def setVidremonta(self,value):self.__vidremonta=value
- def setSpeciall(self,value):self.__speciall=value
- def setCode(self,value):self.__code=value
- def getVidstanka(self):return self.__vidstanka
- def getData(self):return self.__data
- def getVidremonta(self):return self.__vidremonta
- def getSpeciall(self):return self.__speciall
- def getCode(self):return self.__code
- def info(self):
- s='%s %s %s %s %s %s %s %s %s %s %s %s'%(self.__vidstanka.getCountry(),self.__vidstanka.getYear(),self.__vidstanka.getMark(),self.__vidstanka.getCode(),self.__vidremonta.getName(),self.__vidremonta.getTime(),self.__vidremonta.getCost(),self.__vidremonta.getSpecial(),self.__vidremonta.getCode(),self.getData(),self.getSpeciall(),self.getCode())
- return(s)
- class RemontlistEdit(generallistEdit):
- def newRec (self,vidstanka='',data='',vidremonta='',speciall='',code=0):
- self.appendList(Remont(vidstanka,data,vidremonta,speciall,code))
- def setVidstanka(self,code,value):self.findByCode(code).setVidstanka(value)
- def setData(self,code,value):self.findByCode(code).setData(value)
- def setVidremonta(self,code,value):self.findByCode(code).setVidremonta(value)
- def setSpeciall(self,code,value):self.findByCode(code).setSpeciall(value)
- def getVidstanka(self,code):return self.findByCode(code).getVidstanka()
- def getData(self,code):return self.findByCode(code).getData()
- def getVidremonta(self,code):return self.findByCode(code).getVidremonta()
- def getSpeciall(self,code):return self.findByCode(code).getSpeciall()
- class Remontstankov :
- def __init__(self):
- self.__Vidstanka=VidstankalistEdit()
- self.__Vidremonta=VidremontalistEdit()
- self.__Remont=RemontlistEdit()
- def removeVidstanka(self,code):
- b = True
- for c in self.getRemontCodes():
- if self.getRemontVidstankaCode(c) == code:
- b = False
- break
- if b:
- self.__Vidstanka.removeList(code)
- def removeVidremonta(self,code):
- d = True
- for e in self.getRemontCodes():
- if self.getRemontVidremontaCode(e) == code:
- d = False
- break
- if d:
- self.__Vidremonta.removeList(code)
- def clear(self):
- self.__Vidstanka.clear()
- self.__Vidremonta.clear()
- self.__Remont.clear()
- def removeVidstanka(self,code):
- self.__Vidstanka.removeList(code)
- for c in self.__Remont.getCodes():
- self.Remont.serVidstanka(c,None)
- def newVidstanka(self,country='',year=0,mark='',code=0):
- self.__Vidstanka.newRec(country,year,mark,code)
- def FindVidstankaByCode(self,code):return self.__Vidstanka.findByCode(code)
- def setVidstankaCountry(self,code,value): self.__Vidstanka.setCountry(code, value)
- def setVidstankaYear(self,code,value): self.__Vidstanka.setYear(code, value)
- def setVidstankaMark(self,code,value): self.__Vidstanka.setMark(code, value)
- def getVidstankaNewCode(self): return self.__Vidstanka.getNewCode()
- def getVidstankaCodes(self): return self.__Vidstanka.getCodes()
- def getVidstankaCountry(self,code): return self.__Vidstanka.getCountry(code)
- def getVidstankaYear(self,code): return self.__Vidstanka.getYear(code)
- def getVidstankaMark(self,code): return self.__Vidstanka.getMark(code)
- def removeVidremonta(self,code):
- self.__Vidremonta.removeList(code)
- for c in self.__Remont.getCodes():
- self.Remont.serVidremonta(c,None)
- def newVidremonta(self,name='',time=0,cost=0,special='',code=0):
- self.__Vidremonta.newRec(name,time,cost,special,code)
- def FindVidremontaByCode(self,code):return self.__Vidremonta.findByCode(code)
- def setVidremontaName(self,code,value): self.__Vidremonta.setName(code, value)
- def setVidremontaTime(self,code,value): self.__Vidremonta.setTime(code, value)
- def setVidremontaCost(self,code,value): self.__Vidremonta.setCost(code, value)
- def setVidremontaSpecial(self,code,value): self.__Vidremonta.setSpecial(code, value)
- def getVidremontaNewCode(self): return self.__Vidremonta.getNewCode()
- def getVidremontaCodes(self): return self.__Vidremonta.getCodes()
- def getVidremontaName(self,code): return self.__Vidremonta.getName(code)
- def getVidremontaTime(self,code): return self.__Vidremonta.getTime(code)
- def getVidremontaCost(self,code): return self.__Vidremonta.getCost(code)
- def getVidremontaSpecial(self,code): return self.__Vidremonta.getSpecial(code)
- def removeRemont(self,code):
- self.__Remont.removeList(code)
- def newRemont(self,vidstanka='',data='',vidremonta='',speciall='',code=0):
- self.__Remont.newRec(vidstanka,data,vidremonta,speciall,code)
- def FindRemontByCode(self,code):return self.__Remont.findbycode(code)
- def setRemontVidstanka(self,code,value): self.__Remont.setVidstanka(code, value)
- def setRemontData(self,code,value): self.__Remont.setData(code, value)
- def setRemontVidremonta(self,code,value): self.__Remont.setVidremonta(code, value)
- def setRemontSpeciall(self,code,value): self.__Remont.setSpeciall(code, value)
- def getRemontCodes(self): return self.__Remont.getCodes()
- def getRemontNewCodes(self): return self.__Remont.getNewCodes()
- def getRemontVidstanka(self,code): return self.__Remont.getVidstanka(code)
- def getRemontData(self,code): return self.__Remont.getData(code)
- def getRemontVidremonta(self,code): return self.__Remont.getVidremonta(code)
- def getRemontSpeciall(self,code): return self.__Remont.getSpeciall(code)
- #def getRemontVidstankaCode(self, code): return self.__remont.getVidstankaCode(code)
- #def getRemontVidstankaCountry(self, code): return self.__remont.getVidstankaCountry(code)
- #def getRemontVidstankaYear(self, code): return self.__remont.getVidstankaYear(code)
- #def getRemontVidstankaMark(self, code): return self.__remont.getVidstankaMark(code)
- #def getRemontVidremontaCode(self, code): return self.__remont.getVidremontaCode(code)
- #def getRemontVidremontaName(self, code): return self.__remont.getVidremontaName(code)
- #def getRemontVidremontaTime(self, code): return self.__remont.getVidremontaTime(code)
- #def getRemontVidremontaCost(self, code): return self.__remont.getVidremontaCost(code)
- #def getRemontVidremontaSpecial(self, code): return self.__remont.getVidremontaSpecial(code)
- def RemontInfo(self, code): return self.__remont.info(code)
- class dataxml:
- def read(self, inp, hos):
- dom = xml.dom.minidom.parse(inp)
- dom.normalize()
- for node in dom.childNodes[0].childNodes:
- if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Vidstanka'):
- country,year,mark,code ='',0,'',0
- for t in node.attributes.items():
- if t[0] == "country": country = t[1]
- if t[0] == "year": year = int(t[1])
- if t[0] == "mark": mark = t[1]
- if t[0] == "code": code = int(t[1])
- hos.newVidstanka(country,year,mark,code)
- if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Vidremonta'):
- name,time,cost,special,code ='',0,0,'',0
- for t in node.attributes.items():
- if t[0] == "name": name = t[1]
- if t[0] == "time": time = t[1]
- if t[0] == "cost": cost = t[1]
- if t[0] == "special": special = t[1]
- if t[0] == "code": code = int(t[1])
- hos.newVidremonta(name,time,cost,special,code)
- if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Remont'):
- vidstanka,data,vidremonta,speciall,code ='','','','',0
- for t in node.attributes.items():
- if t[0] == "vidstanka": vidstanka = hos.FindVidstankaByCode(int(t[1]))
- if t[0] == "data": data = t[1]
- if t[0] == "vidremonta": vidremonta = hos.FindVidremontaByCode(int(t[1]))
- if t[0] == "speciall": speciall = t[1]
- if t[0] == "code": code = int(t[1])
- hos.newRemont(vidstanka,data,vidremonta,speciall,code)
- for n in node.childNodes:
- if (n.nodeType==n.ELEMENT_NODE) and (n.nodeName=='vidstanka'):
- for t in n.attributes.items():
- if t[0]=="code":vidstanka=hos.FindVidstankaByCode(int(t[1]))
- hos.appendRemontVidstanka(code,Vidstanka)
- for n in node.childNodes:
- if (n.nodeType==n.ELEMENT_NODE) and (n.nodeName=='vidremonta'):
- for t in n.attributes.items():
- if t[0]=="code":vidremonta=hos.FindVidremontaByCode(int(t[1]))
- hos.appendRemontVidremonta(code,Vidremonta)
- def write(self, out, hos):
- dom = xml.dom.minidom.Document()
- root = dom.createElement("Remontstankov")
- dom.appendChild(root)
- for c in hos.getVidstankaCodes():
- vsk = dom.createElement("vidstanka")
- vsk.setAttribute('country', hos.getVidstankaCountry(c))
- vsk.setAttribute('year', str(hos.getVidstankaYear(c)))
- vsk.setAttribute('mark', hos.getVidstankaMark(c))
- vsk.setAttribute('code', str(c))
- root.appendChild(vsk)
- for c in hos.getVidremontaCodes():
- vrm = dom.createElement("vid")
- vrm.setAttribute('name', hos.getVidremontaName(c))
- vrm.setAttribute('time', str(hos.getVidremontaTime(c)))
- vrm.setAttribute('cost', str(hos.getVidremontaCost(c)))
- vrm.setAttribute('special', hos.getVidremontaSpecial(c))
- vrm.setAttribute('code', str(c))
- root.appendChild(vrm)
- for c in hos.getRemontCodes():
- rem = dom.createElement("Remont")
- rem.setAttribute('vidstanka', str(hos.getRemontVidstanka(c).getCode()))
- rem.setAttribute('data', str(hos.getRemontData(c)))
- rem.setAttribute('vidremonta', str(hos.getRemontVidremonta(c).getCode()))
- rem.setAttribute('speciall', hos.getRemontSpeciall(c))
- rem.setAttribute('code', str(c))
- root.appendChild(rem)
- f = open(out, "w")
- f.write(dom.toprettyxml())
- vs1=Vidstanka('Russia',2000,'Bosh',0)
- vr1=Vidremonta('Top342',2,40,'brokenbutton',0)
- r1=Remont(vs1,'20072019',vr1,'brokenbutton1',0)
- print(r1.info())
- rem1 = Remontstankov()
- dat1 = dataxml()
- dat1.read('old.xml', rem1)
- rem1.newVidstanka('Russia',2000,'Bosh',0)
- rem1.newVidremonta('Top342',2,40,'brokenbutton',0)
- rem1.newRemont(rem1.FindVidstankaByCode(1),'20072019',rem1.FindVidremontaByCode(1),'brokenbutton1',0)
- rem1.removeRemont(1)
- rem1.removeVidstanka(1)
- rem1.removeVidremonta(1)
- dat1.write('new.xml', rem1)
- <Remontstankov>
- <Vidstanka country = 'Russia' year= '2000' mark = 'Bosh' code= '1' />
- <Vidremonta name = 'Top342' time = '2' cost = '40' special = 'brokenbutton' code= '1'/>
- <Remont vidstanka= '1' data = '20.07.2019' vidremonta = '1' speciall = 'brokenbutton1' code = '1'>
- </Remont>
- </Remontstankov>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement