updated Commander
authorMarius Sandu-Popa <sandupopamarius@gmail.com>
Thu, 15 Apr 2010 12:19:20 +0000 (15:19 +0300)
committerMarius Sandu-Popa <sandupopamarius@gmail.com>
Thu, 15 Apr 2010 12:19:36 +0000 (15:19 +0300)
autorun/commander/Commander.py
autorun/commander/XMLParser.py

index a1b4a4f..70ac5d8 100644 (file)
@@ -111,12 +111,15 @@ class Commander(Thread):
                                LOG_FILE : si.log_file,
                                TORRENT : torrent_file }
                
-               self.printDummyCommand(node.public_address, node.listen_port, START_MSG, config_data)
-               response = self.sendComm(node.public_address, 
+               #self.printDummyCommand(node.public_address, node.listen_port, START_MSG, config_data)
+               msg_type, msg_data = self.sendComm(node.public_address, 
                                        int(node.listen_port), 
                                        START_MSG, 
                                        config_data)
-               switch(a):
+               if(msg_type == ACK_MSG):
+                       si.pid = msg_data
+               else:
+                       print msg_data          
        
        def printDummyCommand(self, public_address, public_port, option1, data):
                print "----------------------"
@@ -125,10 +128,22 @@ class Commander(Thread):
                print "----------------------\n"
                
        
-       def sendSIStop(self, node):
-               pass
-               
-       def sendSIStatus(self, node):
+       def sendSIStop(self, si):       
+               #self.printDummyCommand(node.public_address, node.listen_port, START_MSG, config_data)
+               node = self.nodes.getNodeBySi(si)
+               msg_type, msg_data = self.sendComm(node.public_address, 
+                                       int(node.listen_port), 
+                                       STOP_MSG,
+                                       si.pid) 
+                       
+               if(msg_type == ACK_MSG):
+                       "shutdown client OK"
+               else:
+                       "error while shutting down client"
+                       print msg_data          
+       
+
+       def sendSIStatus(self, si):
                pass
        
        def startAll(self):
index bb87da9..82c1fe9 100644 (file)
@@ -3,6 +3,7 @@ from lxml import etree
 class SwarmInstance:
        def __init__(self, id, list):
                self.id = id;
+               self.pid = -1;
                self.node_id = list[0];
                self.btclient = list[1];
                self.upload_limit = list[2];
@@ -13,6 +14,9 @@ class SwarmInstance:
                self.output_dir = list[7];
                self.output_file = list[8];
        
+       def setPid(self, pid):
+               self.pid = pid;
+
        def __str__(self):
                return '[%s: %s: %s: %s: %s: %s: %s: %s]' \
                        %(self.id, self.node_id, self.btclient, self.upload_limit, \
@@ -33,7 +37,7 @@ class Node:
                self.daemon_dir = list[9];
                self.daemon_file = list[10];
                self.clients_base_dir = list[11];
-               self.clients = {};
+#              self.clients = {};
        
        def __str__(self):
                return '[%s: %s: %s: %s: %s: %s %s: %s]' \
@@ -42,6 +46,15 @@ class Node:
        
        def getClientBaseDir(self, client):
                return self.clients_base_dir[client]
+#
+#      def addClient(self, name, id):
+#              if(name not in self.clients):
+#                      self.clients[name] = [id];
+#              else: 
+#                      self.clients[name].append(id);
+#              
+#      def getRunningClients(self, name):
+#              return self.clients[name];
 
 class Nodes:
        def __init__(self, nodes_xml):
@@ -106,7 +119,13 @@ class Swarm:
 #~ for si in swarm.getSIs():
        #~ print si
 
-#~ nodes = Nodes("nodes.xml")
-#~ for node in nodes.getNodes():
-       #~ print node
+#nodes = Nodes("../xml/nodes.xml")
+#for node in nodes.getNodes():
+#      print node
+#node = nodes.getNode("1");
+#print node
+#node.addClient("tribler", 23131);
+##node.addClient("tribler", 33333);
+#node.addClient("adadsa", 99999);
+#print node.clients;
        #~ print node.getClientBaseDir('libtorrent')