From: Marius Sandu-Popa Date: Sun, 31 Jan 2010 20:44:54 +0000 (+0200) Subject: some minor changes to client.py X-Git-Tag: getopt_long~186 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=353610633da740579538f16c569ffc16f9819d3b;p=cs-p2p-next.git some minor changes to client.py --- diff --git a/bt_comm/client/Client.py b/bt_comm/client/Client.py index bd7ceb9..dbd4c78 100644 --- a/bt_comm/client/Client.py +++ b/bt_comm/client/Client.py @@ -5,6 +5,7 @@ import os from Util import * from XMLParser import * from TrafficControl import * +from threading import Thread paramiko.util.log_to_file('/tmp/paramiko.log') MSGLEN = 1024 @@ -19,9 +20,21 @@ class Commander(Thread): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def send_sshcomm(self, hostname, username, port, comm): - self.sshc.connect(hostname=hostname, username=username, port=port) - stdin, stdout, stderr = self.sshc.exec_command(comm) - self.sshc.close() + try: + self.sshc.connect(hostname=hostname, username=username, port=port) + stdin, stdout, stderr = self.sshc.exec_command(comm) + self.sshc.close() + except Exception as e: + print e + + def send_multiple_sshcom(self, hostname, username, port, comms): + try: + self.sshc.connect(hostname=hostname, username=username, port=port) + for c in comms: + stdin, stdout, stderr = self.sshc.exec_command(comm) + self.sshc.close() + except Exception as e: + print e def send_comm(self, hostname, port, msg_type, config_data): self.sock.connect((hostname, port)) @@ -44,7 +57,7 @@ class Commander(Thread): def start_daemon(self, node): comm = ""; - send_sshcomm(node.public_address, node.username, node.ssh_port, comm): + send_sshcomm(node.public_address, node.username, node.ssh_port, comm) def apply_tc(self, node): si = swarm.getSIByNode(node) @@ -53,18 +66,18 @@ class Commander(Thread): tc.set_upload_limit(si.upload_limit) tc.set_download_limit(si.downoad_limit) - upload_limit_commands = tc.get_upload_limit_commands() - download_limit_commands = tc.get_download_limit_commands() - flush_commands = tc.get_flush_commands() + commands = tc.get_all_commands() + send_multiple_sshcomm(node.public_address, node.username, node.ssh_port, commands) def send_start(self, node): + config_data = [] #~ config_data = [{CLIENT:"tribler", FILE:"Tribler/Tools/cmdline.py", #~ RUN_TYPE:"script", #~ INTERPRETER:"python", PREFIX:"PYTHONPATH=.",SUFFIX:"", #~ UP_LIMIT_OPTION:"",DL_LIMIT_OPTION:"", PORT_OPTION:"-p", #~ LOG_DIR_OPTION:"-l",DL_DIR_OPTION:"-d"}] - response = send_comm(self, node.public_address, node.public_port, START_MSG, config_data): + response = send_comm(self, node.public_address, node.public_port, START_MSG, config_data) def send_stop(self, node): pass @@ -73,9 +86,10 @@ class Commander(Thread): pass def run(self): - pass - - + while(1): + k = raw_input('enter choice:') + if k == '': break + #~ def recv_msg(self): #~ msg = '' #~ chunk = self.sock.recv(MSGLEN) @@ -89,7 +103,7 @@ class TestCommander: def __init__(self): nodes = Nodes("../xml/nodes.xml"); swarm = Swarm("../xml/swarm.xml"); - print nodes.getNode("2"); + #print nodes.getNode("2"); if __name__ == "__main__": diff --git a/bt_comm/client/TrafficControl.py b/bt_comm/client/TrafficControl.py index 27d8be2..1399e03 100644 --- a/bt_comm/client/TrafficControl.py +++ b/bt_comm/client/TrafficControl.py @@ -67,6 +67,14 @@ class TrafficControl: return flush_commands + def get_all_commands(self): + all_commands = [] + all_commands.extend(self.get_upload_limit_commands()) + all_commands.extend(self.get_download_limit_commands()) + all_commands.extend(self.get_flush_commands()) + + return all_commands + def print_commands(commands, header): print "\n\t== %s ==\n" % (header) @@ -89,10 +97,12 @@ def main(): upload_limit_commands = tc.get_upload_limit_commands() download_limit_commands = tc.get_download_limit_commands() flush_commands = tc.get_flush_commands() + all_commands = tc.get_all_commands() print_commands(upload_limit_commands, "upload limit commands") print_commands(download_limit_commands, "download limit commands") print_commands(flush_commands, "flush commands") + print_commands(all_commands, "all commands") if __name__ == "__main__": sys.exit(main()) diff --git a/bt_comm/xml/XMLParser.py b/bt_comm/xml/XMLParser.py index 928c654..a9e0cda 100644 --- a/bt_comm/xml/XMLParser.py +++ b/bt_comm/xml/XMLParser.py @@ -78,6 +78,6 @@ class Swarm: if si.node_id == node.id: return si -sw = Swarm("swarm.xml"); -print sw.torrent_file -print sw.getSIByNode("1") +#sw = Swarm("swarm.xml"); +#print sw.torrent_file +#print sw.getSIByNode("1")