Advertisement
Guest User

Untitled

a guest
Jun 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2. from paramiko import SSHClient, AutoAddPolicy
  3. from scp import SCPClient
  4.  
  5. HOST='snowwhite.disi.unitn.eu'
  6. USER='sottovia'
  7. PWD='19021990'
  8.  
  9. def copy_files(string):
  10. ssh = SSHClient()
  11. ssh.load_system_host_keys()
  12. ssh.connect(HOST, username=USER, password=PWD)
  13. ssh.set_missing_host_key_policy(AutoAddPolicy())
  14. print("echo \"{}\">> /tmp/testo.txt".format(string))
  15. stdin, stdout, stderr = ssh.exec_command("echo \"{}\">> /tmp/testo.txt".format(string))
  16. stdin.flush()
  17.  
  18.  
  19. def parse_xml(root):
  20. #Set of dictionaries
  21. elements = []
  22. keys = []
  23.  
  24. #Set of keys
  25.  
  26. for child in root.iter('program'):
  27. #print(child)
  28. print("Element: ")
  29.  
  30. map = {}
  31.  
  32. for c in child.iter('entry'):
  33. keys.append(c.get('key'))
  34. map[c.get('key')] = c.get('value')
  35. print(c.get('key'), c.get('value'))
  36.  
  37. elements.append(map)
  38. # for child in root.findall('program'):
  39. # print(child)
  40.  
  41.  
  42. # for child in root.iter():
  43. # #print (child)
  44. # print(child.tag, child.attrib)
  45.  
  46. keys = set(keys)
  47. print(keys)
  48. orderedParameters =sorted(keys)
  49. print(orderedParameters)
  50. print(len(orderedParameters))
  51.  
  52. s = ''
  53. for el in elements:
  54. for k in orderedParameters:
  55. # print("key: ",k," value ",el.get(k, None))
  56. s += el.get(k, 'NULL') + ','
  57. s = s[:-1] + '\n'
  58. copy_files(s[:-1])
  59.  
  60.  
  61.  
  62. if __name__ == '__main__':
  63. path = '/Users/paolosottovia/Downloads/SaideaXMLdata/processList.xml'
  64. path1 = '/Users/paolosottovia/Downloads/SaideaXMLdata/networkConfig.xml'
  65. with open(path, 'r') as myfile:
  66. data=myfile.read()
  67. print(data)
  68.  
  69. root = ET.fromstring(data)
  70.  
  71. print(root.tag)
  72. print(root.attrib)
  73. print("Childrens: ")
  74. print(root.get('executionresults'))
  75. parse_xml(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement