Kosty_Fomin

Untitled

Jan 12th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from xml.etree.ElementTree import Element, SubElement, Comment, tostring
  5. import os
  6.  
  7. f = str(os.system("sudo fdisk -l"))
  8. #f = open('file.txt')
  9.  
  10. top = Element('Disks')
  11.  
  12. def crDiskElement(info, top):
  13. child = SubElement(top, 'Disk')
  14. childDiskPath = SubElement(child,'Path')
  15. childDiskPath.text = info[1][:-1]
  16. childDiskSize = SubElement(child,'Size')
  17. childDiskSize.text = info[2]+" "+info[3][:-1]
  18. childDiskSectors = SubElement(child,'Sectors')
  19. childDiskSectors.text = info[6]
  20. return top
  21.  
  22. for line in f:
  23. l = line.split(" ")
  24. for element in l:
  25. if element.decode('utf-8') == 'Диск'.decode('utf-8'):
  26. top = crDiskElement(l,top)
  27. else:
  28. pass
  29.  
  30.  
  31. text_file = open("Output.xml", "w")
  32. text_file.write(tostring(top))
  33. text_file.close()
  34.  
  35. #print tostring(top)
Advertisement
Add Comment
Please, Sign In to add comment