From: Marius Sandu-Popa Date: Tue, 19 Jan 2010 13:21:28 +0000 (+0200) Subject: parse xml files X-Git-Tag: getopt_long~219 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=5ffd71400d355bf78a081ad2846b6fdadc85153a;p=cs-p2p-next.git parse xml files --- diff --git a/razvan/xml/clients.xml b/razvan/xml/clients.xml index 636ccde..57c96da 100644 --- a/razvan/xml/clients.xml +++ b/razvan/xml/clients.xml @@ -3,19 +3,22 @@ Tribler/Tools/cmdline.py - python + python PYTHONPATH=. -p - -l + -l -d hrktorrent + + + -p -d @@ -23,11 +26,14 @@ src/transmission-cli + + + -u -d -p - -l + -l -o diff --git a/razvan/xml/conf.py b/razvan/xml/conf.py new file mode 100644 index 0000000..e69de29 diff --git a/razvan/xml/swarm.xml b/razvan/xml/swarm.xml index be6b041..e0ba485 100644 --- a/razvan/xml/swarm.xml +++ b/razvan/xml/swarm.xml @@ -3,11 +3,11 @@ 1 triber - - - - - + 512 + 256 + 9999 + /this/dir + /this/dir diff --git a/razvan/xml/test.py b/razvan/xml/test.py new file mode 100644 index 0000000..ea5f75e --- /dev/null +++ b/razvan/xml/test.py @@ -0,0 +1,94 @@ +from lxml import etree + +class SwarmInstance: + def __init__(self, id, list): + self.id = id; + self.node_id = list[0]; + self.btclient = list[1]; + self.upload_limit = list[2]; + self.download_limit = list[3]; + self.port = list[4]; + self.download_dir = list[5]; + self.upload_dir = list[6]; + + def __str__(self): + return '[%s: %s: %s: %s: %s: %s: %s: %s]' \ + %(self.id, self.node_id, self.btclient, self.upload_limit, \ + self.download_limit, self.port, self.upload_dir, self.download_dir); + +class NodeConfig: + def __init__(self, list): + self.id = list[0]; + self.public_address = list[1]; + self.public_port = list[2]; + self.private_address = list[3]; + self.private_port = list[4]; + self.ssh_port= list[5]; + self.clients_base_dir = list[6]; + + #~ def __str__(self): + #~ return '[%s: %s: %s: %s: %s: %s: %s]' \ + #~ %(self.id, self.btclient, self.upload_limit, self.download_limit, self.port, self.upload_dir, self.download_dir); + +class ClientConfig: + def __init__(self, id, node_path, filetype, options): + self.id = id; + self.node_path = node_path; + self.filetype = filetype; + self.options = options; + #~ self.upload_limit_option= list[2]; + #~ self.download_limit_option = list[3]; + #~ self.port_option = list[4]; + #~ self.logging_dir_option = list[5]; + #~ self.download_dir_option = list[6]; + + #~ def __str__(self): + #~ return '[%s: %s: %s: %s: %s: %s: %s]' \ + #~ %(self.id, self.btclient, self.upload_limit, self.download_limit, self.port, self.upload_dir, self.download_dir); + +class FileType: + def __init__(self, list): + self.type = list[0]; + self.file = list[1]; + self.interpreter = list[2]; + self.prefix = list[3]; + self.sufix = list[4]; + + def __str__(self): + return '[%s: %s: %s: %s: %s: %s: %s]' \ + %(self.id, self.btclient, self.upload_limit, self.download_limit, self.port, self.upload_dir, self.download_dir); + +#~ tree = etree.parse("swarm.xml") +#~ root = tree.getroot() +#~ for elem in root: + #~ swn = SwarmInstance(elem.get("id"), [elemelem.text for elemelem in elem]) + #~ print swn + #~ print "==================================" + +try: + tree = etree.parse("clients.xml") + root = tree.getroot() + dict = {} + for elem in root: + id = elem.get("id") + options = [elem2.text for elem2 in elem[1:]] + filetype = [elem[0].get("type")] + filetype.extend([elem2.text for elem2 in elem[0]]) + dict[id] = [options, filetype] +except IOError as e: + print e + +try: + tree = etree.parse("nodes.xml") + root = tree.getroot() + for elem in root: + list = [elem.get("id")] + list.extend([elem2.text for elem2 in elem[:len(elem)-1]]) + dict = {} + for elem2 in elem[len(elem)-1]: + dict[elem2.get("id")]=elem2[0].text; + list.append(dict) + print list + print "==================================" +except IOError as e: + print e diff --git a/razvan/xml/test2.py b/razvan/xml/test2.py new file mode 100644 index 0000000..23d4639 --- /dev/null +++ b/razvan/xml/test2.py @@ -0,0 +1,18 @@ +import paramiko +import os +paramiko.util.log_to_file('/tmp/paramiko.log') + +client = paramiko.SSHClient() +client.load_system_host_keys() +client.connect(hostname='p2p-next-07.grid.pub.ro', username='p2p') +stdin, stdout, stderr = client.exec_command('ls -l') + +#~ host = "p2p-next-09.grid.pub.ro" +#~ port = 22 +#~ transport = paramiko.Transport((host, port)) + +#~ privatekeyfile = os.path.expanduser('~/.ssh/id_rsa') +#~ mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile) +#~ username = 'p2p' +#~ transport.connect(username = username, pkey = mykey) +