From ab6a58c749397d376f92172a577390d043b6c74c Mon Sep 17 00:00:00 2001 From: P2P-Next Date: Fri, 21 May 2010 18:21:55 +0300 Subject: [PATCH] autorun: tested Hrktorrent with logging --- autorun/server/BitTorrentClientRun.py | 12 ++++++++---- autorun/server/Client.py | 2 +- autorun/server/HrktorrentRun.py | 21 +++++++++++++++++++-- autorun/server/start-server | 1 + 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/autorun/server/BitTorrentClientRun.py b/autorun/server/BitTorrentClientRun.py index 7115372..018a1d2 100644 --- a/autorun/server/BitTorrentClientRun.py +++ b/autorun/server/BitTorrentClientRun.py @@ -19,7 +19,6 @@ class BitTorrentClientRun: self.base_path = base_path self.simple_run_expr = simple_run_expr self.logging_run_expr = logging_run_expr - self.my_logger = logging.getLogger('autorun.BitTorrentClientRun') self.my_logger.setLevel(logging.DEBUG) @@ -59,7 +58,7 @@ class BitTorrentClientRun: print self.simple_run_command print self.logging_run_command - + def run_client(self, command): try: # split command @@ -73,16 +72,20 @@ class BitTorrentClientRun: #self.my_logger.debug(" BitTorrentClientRun: command =" + str(args)) 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 = open("/tmp/err","w") # because hrktorrent does not have logs at stderr output + log_redirect = None if self.log_file != "": 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 + log_redirect = open("/dev/null","w") # because hrktorrent does not have logs at stderr output + p=subprocess.Popen(args, shell=False, #does not create sh process stdout=output_redirect, stderr=log_redirect) pid = p.pid self.my_logger.debug(" BitTorrentClientRun: pid = " + str(pid)) + print " BitTorrentClientRun: pid = ", str(pid) return [pid, log_redirect, output_redirect] except Exception, ex: @@ -93,7 +96,8 @@ class BitTorrentClientRun: if pid != None: os.kill(int_pid, signal.SIGKILL) # kill generates zombies os.wait() - raise Exception + + raise def main(): diff --git a/autorun/server/Client.py b/autorun/server/Client.py index a4d6c1a..fd4d1fe 100644 --- a/autorun/server/Client.py +++ b/autorun/server/Client.py @@ -107,7 +107,7 @@ def test_all_commands(torrent_file): start_data_hrktorrent = { CLIENT: HRKTORRENT, PORT:10350, - BASE_DIR:"/home/p2p/p2p-clients/hrktorrent", + BASE_DIR:"/home/p2p/p2p-clients/hrktorrent-logging/hrktorrent", TORRENT: "/home/p2p/p2p-meta/" + torrent_name+".torrent", DL_DIR: "/home/p2p/p2p-dld/hrktorrent", LOG_DIR: "/home/p2p/p2p-dld/hrktorrent", diff --git a/autorun/server/HrktorrentRun.py b/autorun/server/HrktorrentRun.py index 540f494..8debcf8 100644 --- a/autorun/server/HrktorrentRun.py +++ b/autorun/server/HrktorrentRun.py @@ -8,6 +8,7 @@ import sys import os.path from BitTorrentClientRun import BitTorrentClientRun +from Util import * DEBUG = False @@ -25,9 +26,25 @@ def main(): Test case """ - hr = HrktorrentRun("/home/p2p/p2p-clients/hrktorrent") - hr.config_run("/home/p2p/p2p-dld/hrktorrent", "/home/p2p/p2p-log/hrktorrent", "hrktorrent-fedora.out", "/home/p2p/p2p-log/hrktorrent", "hrktorrent-fedora.log", 10150, "/home/p2p/p2p-meta/fedora.torrent") + bt_client_data = { + CLIENT: HRKTORRENT, PORT:10350, + BASE_DIR:"/home/p2p/p2p-clients/hrktorrent-logging/hrktorrent", + TORRENT: "/home/p2p/p2p-meta/test.torrent", + DL_DIR: "/home/p2p/p2p-dld/hrktorrent", + LOG_DIR: "/home/p2p/p2p-dld/hrktorrent", + OUT_DIR: "/home/p2p/p2p-log/hrktorrent", + OUT_FILE: "test.out", #status messages + LOG_FILE: "", #verbose messages + + + } + hr = HrktorrentRun("/home/p2p/p2p-clients/hrktorrent-logging/hrktorrent") + hr.config_run(bt_client_data[DL_DIR], bt_client_data[OUT_DIR], + bt_client_data[OUT_FILE], bt_client_data[LOG_DIR], + bt_client_data[LOG_FILE], bt_client_data[PORT], + bt_client_data[TORRENT]) hr.start() + hr.run_client(hr.simple_run_command) if __name__ == "__main__": diff --git a/autorun/server/start-server b/autorun/server/start-server index 18c6618..d4032f6 100755 --- a/autorun/server/start-server +++ b/autorun/server/start-server @@ -6,5 +6,6 @@ if test $# -ne 1; then fi ip_address=$1 +LD_LIBRARY_PATH=/home/p2p/p2p-clients/hrktorrent-logging/libtorrent-rasterbar/lib rm /var/tmp/autorun-server.pid PYTHONPATH=/home/p2p/cs-p2p-next/ppf/log-parser/generic python /home/p2p/cs-p2p-next/autorun/server/Server.py start $ip_address -- 2.20.1