Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.etree.ElementTree as ET
- from paramiko import SSHClient, AutoAddPolicy
- from scp import SCPClient
- HOST='snowwhite.disi.unitn.eu'
- USER='sottovia'
- PWD='19021990'
- def copy_files(string):
- ssh = SSHClient()
- ssh.load_system_host_keys()
- ssh.connect(HOST, username=USER, password=PWD)
- ssh.set_missing_host_key_policy(AutoAddPolicy())
- print("echo \"{}\">> /tmp/testo.txt".format(string))
- stdin, stdout, stderr = ssh.exec_command("echo \"{}\">> /tmp/testo.txt".format(string))
- stdin.flush()
- def parse_xml(root):
- #Set of dictionaries
- elements = []
- keys = []
- #Set of keys
- for child in root.iter('program'):
- #print(child)
- print("Element: ")
- map = {}
- for c in child.iter('entry'):
- keys.append(c.get('key'))
- map[c.get('key')] = c.get('value')
- print(c.get('key'), c.get('value'))
- elements.append(map)
- # for child in root.findall('program'):
- # print(child)
- # for child in root.iter():
- # #print (child)
- # print(child.tag, child.attrib)
- keys = set(keys)
- print(keys)
- orderedParameters =sorted(keys)
- print(orderedParameters)
- print(len(orderedParameters))
- s = ''
- for el in elements:
- for k in orderedParameters:
- # print("key: ",k," value ",el.get(k, None))
- s += el.get(k, 'NULL') + ','
- s = s[:-1] + '\n'
- copy_files(s[:-1])
- if __name__ == '__main__':
- path = '/Users/paolosottovia/Downloads/SaideaXMLdata/processList.xml'
- path1 = '/Users/paolosottovia/Downloads/SaideaXMLdata/networkConfig.xml'
- with open(path, 'r') as myfile:
- data=myfile.read()
- print(data)
- root = ET.fromstring(data)
- print(root.tag)
- print(root.attrib)
- print("Childrens: ")
- print(root.get('executionresults'))
- parse_xml(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement