Advertisement
Guest User

createoop2

a guest
Dec 8th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.91 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 removeVidstanka(self,code):
  123. b = True
  124. for c in self.getRemontCodes():
  125. if self.getRemontVidstankaCode(c) == code:
  126. b = False
  127. break
  128. if b:
  129. self.__Vidstanka.removeList(code)
  130.  
  131. def removeVidremonta(self,code):
  132. d = True
  133. for e in self.getRemontCodes():
  134. if self.getRemontVidremontaCode(e) == code:
  135. d = False
  136. break
  137. if d:
  138. self.__Vidremonta.removeList(code)
  139. def clear(self):
  140. self.__Vidstanka.clear()
  141. self.__Vidremonta.clear()
  142. self.__Remont.clear()
  143.  
  144. def removeVidstanka(self,code):
  145. self.__Vidstanka.removeList(code)
  146. for c in self.__Remont.getCodes():
  147. self.Remont.serVidstanka(c,None)
  148. def newVidstanka(self,country='',year=0,mark='',code=0):
  149. self.__Vidstanka.newRec(country,year,mark,code)
  150. def FindVidstankaByCode(self,code):return self.__Vidstanka.findByCode(code)
  151. def setVidstankaCountry(self,code,value): self.__Vidstanka.setCountry(code, value)
  152. def setVidstankaYear(self,code,value): self.__Vidstanka.setYear(code, value)
  153. def setVidstankaMark(self,code,value): self.__Vidstanka.setMark(code, value)
  154. def getVidstankaNewCode(self): return self.__Vidstanka.getNewCode()
  155. def getVidstankaCodes(self): return self.__Vidstanka.getCodes()
  156. def getVidstankaCountry(self,code): return self.__Vidstanka.getCountry(code)
  157. def getVidstankaYear(self,code): return self.__Vidstanka.getYear(code)
  158. def getVidstankaMark(self,code): return self.__Vidstanka.getMark(code)
  159.  
  160. def removeVidremonta(self,code):
  161. self.__Vidremonta.removeList(code)
  162. for c in self.__Remont.getCodes():
  163. self.Remont.serVidremonta(c,None)
  164. def newVidremonta(self,name='',time=0,cost=0,special='',code=0):
  165. self.__Vidremonta.newRec(name,time,cost,special,code)
  166. def FindVidremontaByCode(self,code):return self.__Vidremonta.findByCode(code)
  167. def setVidremontaName(self,code,value): self.__Vidremonta.setName(code, value)
  168. def setVidremontaTime(self,code,value): self.__Vidremonta.setTime(code, value)
  169. def setVidremontaCost(self,code,value): self.__Vidremonta.setCost(code, value)
  170. def setVidremontaSpecial(self,code,value): self.__Vidremonta.setSpecial(code, value)
  171. def getVidremontaNewCode(self): return self.__Vidremonta.getNewCode()
  172. def getVidremontaCodes(self): return self.__Vidremonta.getCodes()
  173. def getVidremontaName(self,code): return self.__Vidremonta.getName(code)
  174. def getVidremontaTime(self,code): return self.__Vidremonta.getTime(code)
  175. def getVidremontaCost(self,code): return self.__Vidremonta.getCost(code)
  176. def getVidremontaSpecial(self,code): return self.__Vidremonta.getSpecial(code)
  177.  
  178. def removeRemont(self,code):
  179. self.__Remont.removeList(code)
  180. def newRemont(self,vidstanka='',data='',vidremonta='',speciall='',code=0):
  181. self.__Remont.newRec(vidstanka,data,vidremonta,speciall,code)
  182. def FindRemontByCode(self,code):return self.__Remont.findbycode(code)
  183. def setRemontVidstanka(self,code,value): self.__Remont.setVidstanka(code, value)
  184. def setRemontData(self,code,value): self.__Remont.setData(code, value)
  185. def setRemontVidremonta(self,code,value): self.__Remont.setVidremonta(code, value)
  186. def setRemontSpeciall(self,code,value): self.__Remont.setSpeciall(code, value)
  187. def getRemontCodes(self): return self.__Remont.getCodes()
  188. def getRemontNewCodes(self): return self.__Remont.getNewCodes()
  189. def getRemontVidstanka(self,code): return self.__Remont.getVidstanka(code)
  190. def getRemontData(self,code): return self.__Remont.getData(code)
  191. def getRemontVidremonta(self,code): return self.__Remont.getVidremonta(code)
  192. def getRemontSpeciall(self,code): return self.__Remont.getSpeciall(code)
  193. #def getRemontVidstankaCode(self, code): return self.__remont.getVidstankaCode(code)
  194. #def getRemontVidstankaCountry(self, code): return self.__remont.getVidstankaCountry(code)
  195. #def getRemontVidstankaYear(self, code): return self.__remont.getVidstankaYear(code)
  196. #def getRemontVidstankaMark(self, code): return self.__remont.getVidstankaMark(code)
  197. #def getRemontVidremontaCode(self, code): return self.__remont.getVidremontaCode(code)
  198. #def getRemontVidremontaName(self, code): return self.__remont.getVidremontaName(code)
  199. #def getRemontVidremontaTime(self, code): return self.__remont.getVidremontaTime(code)
  200. #def getRemontVidremontaCost(self, code): return self.__remont.getVidremontaCost(code)
  201. #def getRemontVidremontaSpecial(self, code): return self.__remont.getVidremontaSpecial(code)
  202. def RemontInfo(self, code): return self.__remont.info(code)
  203.  
  204.  
  205. class dataxml:
  206.  
  207. def read(self, inp, hos):
  208. dom = xml.dom.minidom.parse(inp)
  209. dom.normalize()
  210. for node in dom.childNodes[0].childNodes:
  211. if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Vidstanka'):
  212. country,year,mark,code ='',0,'',0
  213. for t in node.attributes.items():
  214. if t[0] == "country": country = t[1]
  215. if t[0] == "year": year = int(t[1])
  216. if t[0] == "mark": mark = t[1]
  217. if t[0] == "code": code = int(t[1])
  218. hos.newVidstanka(country,year,mark,code)
  219. if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Vidremonta'):
  220. name,time,cost,special,code ='',0,0,'',0
  221. for t in node.attributes.items():
  222. if t[0] == "name": name = t[1]
  223. if t[0] == "time": time = t[1]
  224. if t[0] == "cost": cost = t[1]
  225. if t[0] == "special": special = t[1]
  226. if t[0] == "code": code = int(t[1])
  227. hos.newVidremonta(name,time,cost,special,code)
  228. if (node.nodeType == node.ELEMENT_NODE) and (node.nodeName == 'Remont'):
  229. vidstanka,data,vidremonta,speciall,code ='','','','',0
  230. for t in node.attributes.items():
  231. if t[0] == "vidstanka": vidstanka = hos.FindVidstankaByCode(int(t[1]))
  232. if t[0] == "data": data = t[1]
  233. if t[0] == "vidremonta": vidremonta = hos.FindVidremontaByCode(int(t[1]))
  234. if t[0] == "speciall": speciall = t[1]
  235. if t[0] == "code": code = int(t[1])
  236. hos.newRemont(vidstanka,data,vidremonta,speciall,code)
  237. for n in node.childNodes:
  238. if (n.nodeType==n.ELEMENT_NODE) and (n.nodeName=='vidstanka'):
  239. for t in n.attributes.items():
  240. if t[0]=="code":vidstanka=hos.FindVidstankaByCode(int(t[1]))
  241. hos.appendRemontVidstanka(code,Vidstanka)
  242. for n in node.childNodes:
  243. if (n.nodeType==n.ELEMENT_NODE) and (n.nodeName=='vidremonta'):
  244. for t in n.attributes.items():
  245. if t[0]=="code":vidremonta=hos.FindVidremontaByCode(int(t[1]))
  246. hos.appendRemontVidremonta(code,Vidremonta)
  247.  
  248.  
  249. def write(self, out, hos):
  250. dom = xml.dom.minidom.Document()
  251. root = dom.createElement("Remontstankov")
  252. dom.appendChild(root)
  253. for c in hos.getVidstankaCodes():
  254. vsk = dom.createElement("vidstanka")
  255. vsk.setAttribute('country', hos.getVidstankaCountry(c))
  256. vsk.setAttribute('year', str(hos.getVidstankaYear(c)))
  257. vsk.setAttribute('mark', hos.getVidstankaMark(c))
  258. vsk.setAttribute('code', str(c))
  259. root.appendChild(vsk)
  260. for c in hos.getVidremontaCodes():
  261. vrm = dom.createElement("vid")
  262. vrm.setAttribute('name', hos.getVidremontaName(c))
  263. vrm.setAttribute('time', str(hos.getVidremontaTime(c)))
  264. vrm.setAttribute('cost', str(hos.getVidremontaCost(c)))
  265. vrm.setAttribute('special', hos.getVidremontaSpecial(c))
  266. vrm.setAttribute('code', str(c))
  267. root.appendChild(vrm)
  268. for c in hos.getRemontCodes():
  269. rem = dom.createElement("Remont")
  270. rem.setAttribute('vidstanka', str(hos.getRemontVidstanka(c).getCode()))
  271. rem.setAttribute('data', str(hos.getRemontData(c)))
  272. rem.setAttribute('vidremonta', str(hos.getRemontVidremonta(c).getCode()))
  273. rem.setAttribute('speciall', hos.getRemontSpeciall(c))
  274. rem.setAttribute('code', str(c))
  275. root.appendChild(rem)
  276. f = open(out, "w")
  277. f.write(dom.toprettyxml())
  278. vs1=Vidstanka('Russia',2000,'Bosh',0)
  279. vr1=Vidremonta('Top342',2,40,'brokenbutton',0)
  280. r1=Remont(vs1,'20072019',vr1,'brokenbutton1',0)
  281. print(r1.info())
  282. rem1 = Remontstankov()
  283. dat1 = dataxml()
  284. dat1.read('old.xml', rem1)
  285. rem1.newVidstanka('Russia',2000,'Bosh',0)
  286. rem1.newVidremonta('Top342',2,40,'brokenbutton',0)
  287. rem1.newRemont(rem1.FindVidstankaByCode(1),'20072019',rem1.FindVidremontaByCode(1),'brokenbutton1',0)
  288. rem1.removeRemont(1)
  289. rem1.removeVidstanka(1)
  290. rem1.removeVidremonta(1)
  291. dat1.write('new.xml', rem1)
  292. <Remontstankov>
  293. <Vidstanka country = 'Russia' year= '2000' mark = 'Bosh' code= '1' />
  294.  
  295.  
  296. <Vidremonta name = 'Top342' time = '2' cost = '40' special = 'brokenbutton' code= '1'/>
  297.  
  298.  
  299. <Remont vidstanka= '1' data = '20.07.2019' vidremonta = '1' speciall = 'brokenbutton1' code = '1'>
  300. </Remont>
  301.  
  302.  
  303. </Remontstankov>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement