Advertisement
Guest User

222222ddd

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