From: P2P-Next Date: Mon, 28 Jun 2010 09:06:51 +0000 (+0300) Subject: autorun: minor changes for hrktorrent X-Git-Tag: getopt_long~14 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=37a9040c72b67b9fce599a3baad3b09a4b50b075;p=cs-p2p-next.git autorun: minor changes for hrktorrent --- diff --git a/autorun/Util.py b/autorun/Util.py index a27ced2..e710800 100644 --- a/autorun/Util.py +++ b/autorun/Util.py @@ -6,6 +6,7 @@ SERVER_FILE = "Server.py" SERVER_TYPE = "python" SERVER_PORT = 10004 SERVER_HOST = "172.16.20.3" + import os def get_sessions_file_path(): dirpath = os.environ['HOME']+"/"+".autorun/" @@ -60,40 +61,3 @@ DHT = "dht" NUM_PEERS = "num_peers" -import os.path -import time -def create_archive_file(file_path): - try: - print "Archive file: ", file_path - - if os.path.isfile(file_path): - # archive file - archive_name = file_path + time.strftime("%d%m%Y_%H%M%S", time.localtime()) + ".zip" - command = "zip " + archive_name + " " + file_path - print command - os.system(command) - # remove file - command = "rm " + file_path - os.system(command) - return 0 - return -1 - except Exception,ex: - raise - - -def create_archive_dir_logs(dir_path): - try: - if not os.path.isfile(dir_path): - # archive all log files - archive_name = dir_path + "/" + "hrk_" + time.strftime("%d%m%Y_%H%M%S", time.localtime()) + ".zip" - command = "zip "+ archive_name + " " + dir_path + "/libtorrent*" + " " + dir_path + "/*log" - print command - os.system(command) - - # remove log files - command = "rm " + dir_path + "libtorrent *" + " " + dir_path + "/*log" - os.system(command) - return 0 - return -1 - except Exception,ex: - raise diff --git a/autorun/server/BitTorrentClientRun.py b/autorun/server/BitTorrentClientRun.py index 018a1d2..af8245f 100644 --- a/autorun/server/BitTorrentClientRun.py +++ b/autorun/server/BitTorrentClientRun.py @@ -59,7 +59,7 @@ class BitTorrentClientRun: print self.simple_run_command print self.logging_run_command - def run_client(self, command): + def run_client(self, command, client): try: # split command args = shlex.split(command) @@ -73,7 +73,7 @@ class BitTorrentClientRun: output_redirect = open(self.output_dir+"/"+self.output_file,"w") self.my_logger.debug(" output redirect to file " + self.output_dir+"/"+self.output_file) log_redirect = None - if self.log_file != "": + if client != HRKTORRENT: log_redirect = open(self.log_dir+"/"+self.log_file,"w") self.my_logger.debug(" log redirect to file " + self.log_dir+"/"+self.log_file) else: #for HRKTORRENT diff --git a/autorun/server/HrktorrentRun.py b/autorun/server/HrktorrentRun.py index 8debcf8..6250476 100644 --- a/autorun/server/HrktorrentRun.py +++ b/autorun/server/HrktorrentRun.py @@ -44,7 +44,7 @@ def main(): bt_client_data[LOG_FILE], bt_client_data[PORT], bt_client_data[TORRENT]) hr.start() - hr.run_client(hr.simple_run_command) + hr.run_client(hr.simple_run_command, HRKTORRENT) if __name__ == "__main__": diff --git a/autorun/server/Server.py b/autorun/server/Server.py index bd00d64..ae42515 100644 --- a/autorun/server/Server.py +++ b/autorun/server/Server.py @@ -81,7 +81,6 @@ class MyDaemon(Daemon): try: f = open(SESSIONS_FILE, 'a') #f.write ("# session " + strftime("%d-%m-%Y %H:%M:%S", localtime())+ "\n") - num_lines = len(data.keys()) if PORT in data: num_lines = num_lines -1; @@ -99,10 +98,47 @@ class MyDaemon(Daemon): self.logger(" Exception while saving transfer info: " + str(ex)) raise + + def create_archive_file(file_path): + try: + print "Archive file: ", file_path + + if os.path.isfile(file_path): + # archive file + archive_name = file_path + time.strftime("%d%m%Y_%H%M%S", time.localtime()) + ".zip" + command = "zip " + archive_name + " " + file_path + print command + os.system(command) + # remove file + command = "rm " + file_path + os.system(command) + return 0 + return -1 + except Exception,ex: + raise + + + def create_archive_dir_logs(dir_path): + try: + if not os.path.isfile(dir_path): + # archive all log files + archive_name = dir_path + "/" + "hrk_" + time.strftime("%d%m%Y_%H%M%S", time.localtime()) + ".zip" + command = "zip "+ archive_name + " " + dir_path + "/libtorrent*" + " " + dir_path + "/*log" + print command + os.system(command) + + # remove log files + command = "rm " + dir_path + "/libtorrent*" + " " + dir_path + "/*log" + os.system(command) + return 0 + return -1 + except Exception,ex: + raise + def add_to_output_msg(self, file_list, info_dict): """ Constructs a list with self.logger file info - paths, client, metafile @param file_list list to which the created self.logger info list in appended. """ - + if CLIENT not in info_dict and TORRENT not in info_dict: return -1 info_list = [info_dict[CLIENT],info_dict[TORRENT]] @@ -243,7 +279,7 @@ class MyDaemon(Daemon): bt_client_data[TORRENT]) btcr.start() - [pid, log_fd, output_fd] = btcr.run_client(btcr.simple_run_command) + [pid, log_fd, output_fd] = btcr.run_client(btcr.simple_run_command, bt_client_data[CLIENT]) self.processes_fd[pid] = [log_fd, output_fd] self.processes_info[pid] = [bt_client_data[CLIENT], bt_client_data[TORRENT],