Advertisement
Guest User

oooop

a guest
Nov 12th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.19 KB | None | 0 0
  1. import os, xml.dom.minidom
  2. class general:
  3. def __init__(self,code=0):
  4. self.setCode(code)
  5. def setCode(self,value): self.__code=value
  6. def getCode(self):return self.__code
  7.  
  8. class generallist :
  9. def __init__(self):self.__list = []
  10. def clear(self): self.__list = []
  11. def findByCode(self,code):
  12. for l in self.__list:
  13. return l
  14. break
  15. def getCodes(self) : return [s.getCode() for s in self.__list]
  16. def appendList (self,value):self.__list.append(value)
  17. def removeList(self,code):
  18. for s in self.__list:
  19. if s.getCode()==code:self.__list.remove(s)
  20.  
  21. class generallistEdit(generallist):
  22. def getNewCode(self):
  23. m=0
  24. for c in self.getCodes():
  25. if c>m:m=c
  26. return m+1
  27. def setName(self,code,value):return self.findByCode(code).setName(value)
  28.  
  29. class Vidstanka(general):
  30. def __init__(self,country='',year=0,mark='',code=0):
  31. self.setCountry(country)
  32. self.setYear(year)
  33. self.setMark(mark)
  34. self.setCode(code)
  35. def setCountry(self,value):self.__country=value
  36. def setYear(self,value):self.__year=value
  37. def setMark(self,value):self.__mark=value
  38. def setCode(self,value):self.__code=value
  39. def getCountry(self):return self.__country
  40. def getYear(self):return self.__year
  41. def getMark(self):return self.__mark
  42. def getCode(self):return self.__code
  43.  
  44. class VidstankalistEdit(generallistEdit):
  45. def newRec (self,country='',year=0,mark='',code=0):
  46. self.appendList(Vidstanka(country,year,mark,code))
  47. def setCountry(self,code,value):self.findByCode(code).setCountry(value)
  48. def setYear(self,code,value):self.findByCode(code).setYear(value)
  49. def setMark(self,code,value):self.findByCode(code).setMark(value)
  50. def getCountry(self,code):return self.findByCode(code).getCountry()
  51. def getYear(self,code):return self.findByCode(code).getYear()
  52. def getMark(self,code):return self.findByCode(code).getMark()
  53.  
  54. class Vidremonta(general):
  55. def __init__(self,name='',time=0,cost=0,special='',code=0):
  56. self.setName(name)
  57. self.setTime(time)
  58. self.setCost(cost)
  59. self.setSpecial(special)
  60. self.setCode(code)
  61. def setName(self,value):self.__name=value
  62. def setTime(self,value):self.__time=value
  63. def setCost(self,value):self.__cost=value
  64. def setSpecial(self,value):self.__special=value
  65. def setCode(self,value):self.__code=value
  66. def getName(self):return self.__name
  67. def getTime(self):return self.__time
  68. def getCost(self):return self.__cost
  69. def getSpecial(self):return self.__special
  70. def getCode(self):return self.__code
  71.  
  72. class VidremontalistEdit(generallistEdit):
  73. def newRec (self,name='',time=0,cost=0,special='',code=0):
  74. self.appendList(Vidremonta(name,time,cost,special,code))
  75. def setName(self,code,value):self.findByCode(code).setName(value)
  76. def setTime(self,code,value):self.findByCode(code).setTime(value)
  77. def setCost(self,code,value):self.findByCode(code).setCost(value)
  78. def setSpecial(self,code,value):self.findByCode(code).setSpecial(value)
  79. def getName(self,code):return self.findByCode(code).getName()
  80. def getTime(self,code):return self.findByCode(code).getTime()
  81. def getCost(self,code):return self.findByCode(code).getCost()
  82. def getSpecial(self,code):return self.findByCode(code).getSpecial()
  83.  
  84. class Remont(general):
  85. def __init__(self,vidstanka='',data='',vidremonta='',speciall='',code=0):
  86. self.setVidstanka(vidstanka)
  87. self.setData(data)
  88. self.setVidremonta(vidremonta)
  89. self.setSpeciall(speciall)
  90. self.setCode(code)
  91. def setVidstanka(self,value):self.__vidstanka=value
  92. def setData(self,value):self.__data=value
  93. def setVidremonta(self,value):self.__vidremonta=value
  94. def setSpeciall(self,value):self.__speciall=value
  95. def setCode(self,value):self.__code=value
  96. def getVidstanka(self):return self.__vidstanka
  97. def getData(self):return self.__data
  98. def getVidremonta(self):return self.__vidremonta
  99. def getSpeciall(self):return self.__speciall
  100. def getCode(self):return self.__code
  101. def info(self):
  102. 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())
  103. return(s)
  104.  
  105. class RemontlistEdit(generallistEdit):
  106. def newRec (self,vidstanka='',data='',vidremonta='',speciall='',code=0):
  107. self.appendList(Remont(vidstanka,data,vidremonta,speciall,code))
  108. def setVidstanka(self,code,value):self.findByCode(code).setVidstanka(value)
  109. def setData(self,code,value):self.findByCode(code).setData(value)
  110. def setVidremonta(self,code,value):self.findByCode(code).setVidremonta(value)
  111. def setSpeciall(self,code,value):self.findByCode(code).setSpeciall(value)
  112. def getVidstanka(self,code):return self.findByCode(code).getVidstanka()
  113. def getData(self,code):return self.findByCode(code).getData()
  114. def getVidremonta(self,code):return self.findByCode(code).getVidremonta()
  115. def getSpeciall(self,code):return self.findByCode(code).getSpeciall()
  116.  
  117. class Remontstankov :
  118. def __init__(self):
  119. self.__Vidstanka=VidstankalistEdit()
  120. self.__Vidremonta=VidremontalistEdit()
  121. self.__Remont=RemontlistEdit()
  122. def clear(self):
  123. self.__Vidstanka.clear()
  124. self.__Vidremonta.clear()
  125. self.__Remont.clear()
  126.  
  127. def removeVidstanka(self,code):
  128. self.__Vidstanka.removeList(self,code)
  129. for c in self.__Remont.getCodes():
  130. self.Remont.serVidstanka(c,None)
  131. def newVidstanka(self,country='',year=0,mark='',code=0):
  132. self.__Vidstanka.newRec(country,year,mark,code)
  133. def FindVidstankaByCode(self,code):return self.__Vidstanka.findbycode(code)
  134. def setVidstankaCountry(self,code,value): self.__Vidstanka.setCountry(code, value)
  135. def setVidstankaYear(self,code,value): self.__Vidstanka.setYear(code, value)
  136. def setVidstankaMark(self,code,value): self.__Vidstanka.setMark(code, value)
  137. def getVidstankaNewCode(self): return self.__Vidstanka.getNewCode()
  138. def getVidstankaCodes(self): return self.__Vidstanka.getCodes()
  139. def getVidstankaCountry(self,code): return self.__Vidstanka.getCountry(code)
  140. def getVidstankaYear(self,code): return self.__Vidstanka.getYear(code)
  141. def getVidstankaMark(self,code): return self.__Vidstanka.getMark(code)
  142.  
  143. def removeVidremonta(self,code):
  144. self.__Vidremonta.removeList(self,code)
  145. for c in self.__Remont.getCodes():
  146. self.Remont.serVidremonta(c,None)
  147. def newVidremonta(self,name='',time=0,cost=0,special='',code=0):
  148. self.__Vidremonta.newRec(name,time,cost,special,code)
  149. def FindVidremontaByCode(self,code):return self.__Vidremonta.findbycode(code)
  150. def setVidremontaName(self,code,value): self.__Vidremonta.setName(code, value)
  151. def setVidremontaTime(self,code,value): self.__Vidremonta.setTime(code, value)
  152. def setVidremontaCost(self,code,value): self.__Vidremonta.setCost(code, value)
  153. def setVidremontaSpecial(self,code,value): self.__Vidremonta.setSpecial(code, value)
  154. def getVidremontaNewCode(self): return self.__Vidremonta.getNewCode()
  155. def getVidremontaCodes(self): return self.__Vidremonta.getCodes()
  156. def getVidremontaName(self,code): return self.__Vidremonta.getName(code)
  157. def getVidremontaTime(self,code): return self.__Vidremonta.getTime(code)
  158. def getVidremontaCost(self,code): return self.__Vidremonta.getCost(code)
  159. def getVidremontaSpecial(self,code): return self.__Vidremonta.getSpecial(code)
  160.  
  161. def removeRemont(self,code):
  162. self.__Remont.removeList(self,code)
  163. def newRemont(self,vidstanka='',data='',vidremonta='',speciall='',code=0):
  164. self.__Remont.newRec(vidstanka,data,vidremonta,speciall,code)
  165. def FindRemontByCode(self,code):return self.__Remont.findbycode(code)
  166. def setRemontVidstanka(self,code,value): self.__Remont.setVidstanka(code, value)
  167. def setRemontData(self,code,value): self.__Remont.setData(code, value)
  168. def setRemontVidremonta(self,code,value): self.__Remont.setVidremonta(code, value)
  169. def setRemontSpeciall(self,code,value): self.__Remont.setSpeciall(code, value)
  170. def getRemontCodes(self): return self.__Remont.getCodes()
  171. def getRemontNewCode(self): return self.__Remont.getNewCode()
  172. def getRemontVidstanka(self,code): return self.__Remont.getVidstanka(code)
  173. def getRemontData(self,code): return self.__Remont.getData(code)
  174. def getRemontVidremonta(self,code): return self.__Remont.getVidremonta(code)
  175. def getRemontSpeciall(self,code): return self.__Remont.getSpeciall(code)
  176. #def getRemontVidstankaCode(self, code): return self.__remont.getVidstankaCode(code)
  177. #def getRemontVidstankaCountry(self, code): return self.__remont.getVidstankaCountry(code)
  178. #def getRemontVidstankaYear(self, code): return self.__remont.getVidstankaYear(code)
  179. #def getRemontVidstankaMark(self, code): return self.__remont.getVidstankaMark(code)
  180. #def getRemontVidremontaCode(self, code): return self.__remont.getVidremontaCode(code)
  181. #def getRemontVidremontaName(self, code): return self.__remont.getVidremontaName(code)
  182. #def getRemontVidremontaTime(self, code): return self.__remont.getVidremontaTime(code)
  183. #def getRemontVidremontaCost(self, code): return self.__remont.getVidremontaCost(code)
  184. #def getRemontVidremontaSpecial(self, code): return self.__remont.getVidremontaSpecial(code)
  185. def RemontInfo(self, code): return self.__remont.info(code)
  186.  
  187.  
  188. class dataxml:
  189.  
  190. def read(self, inp, hos):
  191. dom = xml.dom.minidom.parse(inp)
  192. dom.normalize()
  193. for node in dom.childNodes[0].childNodes:
  194. if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Vidstanka'):
  195. country,year,mark,code ='',0,'',0
  196. for t in node.attributes.items():
  197. if t[0] == "country": country = t[1]
  198. if t[0] == "year": year = t[1]
  199. if t[0] == "mark": mark = t[1]
  200. if t[0] == "code": code = int(t[1])
  201. hos.newVidstanka(country,year,mark,code)
  202. if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Vidremonta'):
  203. name,time,cost,special,code ='',0,0,'',0
  204. for t in node.attributes.items():
  205. if t[0] == "name": name = t[1]
  206. if t[0] == "time": time = t[1]
  207. if t[0] == "cost": cost = t[1]
  208. if t[0] == "special": special = t[1]
  209. if t[0] == "code": code = int(t[1])
  210. hos.newVidremonta(name,time,cost,special,code)
  211. if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Remont'):
  212. vidstanka,data,vidremonta,speciall,code ='','','','',0
  213. for t in node.attributes.items():
  214. if t[0] == "vidstanka": vidstanka = t[1]
  215. if t[0] == "data": data = t[1]
  216. if t[0] == "vidremonta": vidremonta = t[1]
  217. if t[0] == "speciall": speciall = t[1]
  218. if t[0] == "code": code = int(t[1])
  219. hos.newRemont(vidstanka,data,vidremonta,speciall,code)
  220.  
  221. def write(self, out, hos):
  222. dom = xml.dom.minidom.Document()
  223. root = dom.createElement("Remontstankov")
  224. dom.appendChild(root)
  225. for c in hos.getVidstankaCodes():
  226. vsk = dom.createElement("vidstanka")
  227. vsk.setAttribute('country', hos.getVidstankaCountry(c))
  228. #vsk.setAttribute('year', hos.getVidstankaYear(c))
  229. #vsk.setAttribute('mark', hos.getVidstankaMark(c))
  230. #vsk.setAttribute('code', str(c))
  231. #root.appendChild(vsk)
  232. #for c in hos.getVidremontaCodes():
  233. #vrm = dom.createElement("patient")
  234. #vrm.setAttribute('name', hos.getVidremontaName(c))
  235. #vrm.setAttribute('time', hos.getVidremontaTime(c))
  236. #vrm.setAttribute('cost', hos.getVidremontaCost(c))
  237. #vrm.setAttribute('special', hos.getVidremontaSpecial(c))
  238. #vrm.setAttribute('code', str(c))
  239. #root.appendChild(vrm)
  240. #for c in hos.getRemontCodes():
  241. #rem = dom.createElement("Remont")
  242. #rem.setAttribute('vidstanka', hos.getRemontVidstanka(c))
  243. #rem.setAttribute('data', hos.getRemontData(c))
  244. #rem.setAttribute('vidremonta', hos.getRemontVidremonta(c))
  245. #rem.setAttribute('speciall', hos.getRemontSpeciall(c))
  246. #rem.setAttribute('code', str(c))
  247. #root.appendChild(rem)
  248. f = open(out, "w")
  249. f.write(dom.toprettyxml())
  250. vs1=Vidstanka('Russia',2000,'Bosh',0)
  251. vr1=Vidremonta('Top342',2,40,'brokenbutton',0)
  252. r1=Remont(vs1,'20072019',vr1,'brokenbutton1',0)
  253. print(r1.info())
  254. rem1 = Remontstankov()
  255. dat1 = dataxml()
  256. dat1.read('old.xml', rem1)
  257. dat1.write('new.xml', rem1)
  258. #for s in rental1.r1Info():
  259. # print (s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement