parse xml files
authorMarius Sandu-Popa <sandupopamarius@gmail.com>
Tue, 19 Jan 2010 13:21:28 +0000 (15:21 +0200)
committerMarius Sandu-Popa <sandupopamarius@gmail.com>
Tue, 19 Jan 2010 13:21:41 +0000 (15:21 +0200)
razvan/xml/clients.xml
razvan/xml/conf.py [new file with mode: 0644]
razvan/xml/swarm.xml
razvan/xml/test.py [new file with mode: 0644]
razvan/xml/test2.py [new file with mode: 0644]

index 636ccde..57c96da 100644 (file)
@@ -3,19 +3,22 @@
     <client id="tribler">
        <run type="script">
            <file>Tribler/Tools/cmdline.py</file>
-           <interpreter>python</file>
+           <interpreter>python </interpreter>
            <prefix>PYTHONPATH=.</prefix>
            <suffix></suffix>
        </run>
        <upload_limit_option></upload_limit_option>
        <download_limit_option></download_limit_option>
        <port_option>-p</port_option>
-       <logging_dir_option>-l</port_option>
+       <logging_dir_option>-l</logging_dir_option>
        <download_dir_option>-d</download_dir_option>
     </client>
     <client id="libtorrent">
        <run type="executable">
            <file>hrktorrent</file>
+           <interpreter></interpreter>
+           <prefix></prefix>
+           <suffix></suffix>
        </run>
        <port_option>-p</port_option>
        <download_dir_option>-d</download_dir_option>
     <client id="transmission">
        <run type="executable">
            <file>src/transmission-cli</file>
+           <interpreter></interpreter>
+           <prefix></prefix>
+           <suffix></suffix>
        </run>
        <upload_limit_option>-u</upload_limit_option>
        <download_limit_option>-d</download_limit_option>
        <port_option>-p</port_option>
-       <logging_dir_option>-l</port_option>
+       <logging_dir_option>-l</logging_dir_option>
        <download_dir_option>-o</download_dir_option>
     </client>
 </clients>
diff --git a/razvan/xml/conf.py b/razvan/xml/conf.py
new file mode 100644 (file)
index 0000000..e69de29
index be6b041..e0ba485 100644 (file)
@@ -3,11 +3,11 @@
     <instance id="1">
        <node>1</node>
        <client>triber</client>
-       <upload_limit></upload_limit>
-       <download_limit></download_limit>
-       <port></port>
-       <download_dir></download_dir>
-       <logging_dir></logging_dir>
+       <upload_limit>512</upload_limit>
+       <download_limit>256</download_limit>
+       <port>9999</port>
+       <download_dir>/this/dir</download_dir>
+       <logging_dir>/this/dir</logging_dir>
        <actions>
            <action type="start" delay="00:05:00" />
            <action type="stop" delay="00:10:00" />
diff --git a/razvan/xml/test.py b/razvan/xml/test.py
new file mode 100644 (file)
index 0000000..ea5f75e
--- /dev/null
@@ -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 (file)
index 0000000..23d4639
--- /dev/null
@@ -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)
+