From 390b58db5a0a9518b9d224fac64fde20aa7a83c6 Mon Sep 17 00:00:00 2001 From: Adriana Draghici Date: Mon, 28 Jun 2010 14:56:26 +0300 Subject: [PATCH] server: solved libtorrent's verbose logging dir problem --- autorun/server/BitTorrentClientRun.py | 33 +++++++++++++++++++++++---- autorun/server/HrktorrentRun.py | 4 ++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/autorun/server/BitTorrentClientRun.py b/autorun/server/BitTorrentClientRun.py index af8245f..d8612d5 100644 --- a/autorun/server/BitTorrentClientRun.py +++ b/autorun/server/BitTorrentClientRun.py @@ -12,6 +12,7 @@ import subprocess import shlex import logging from string import Template +from Util import * class BitTorrentClientRun: my_logger = None @@ -61,6 +62,11 @@ class BitTorrentClientRun: def run_client(self, command, client): try: + + log_redirect = None + p = None + pid = None + # split command args = shlex.split(command) # remove redirectation parameters @@ -72,16 +78,33 @@ 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 = None + + # start BitTorrent client 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 - 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 + p = subprocess.Popen(args, shell=False, #does not create sh process stdout=output_redirect, stderr=log_redirect) + else: #for HRKTORRENT, verbose logs are not redirected + #set lib env variable !!!!hardcodeeeeeeeeeeeed!!!! + parts = self.base_path.split("/"); + lib_path = "" + for i in range(0, len(parts)-1): + lib_path = lib_path + parts[i]+"/" + lib_path = lib_path + "libtorrent-rasterbar/lib" + os.environ["LD_LIBRARY_PATH"] = lib_path + if not os.path.isdir(self.log_dir): + try: + os.makedirs(self.log_dir) + except OSError,exc: # Python 2.5 + if exc.errno == errno.EEXIST: + pass + else: raise + fd = os.open(self.log_dir, os.O_RDONLY ) + p = subprocess.Popen(args, shell=False, #does not create sh process + stdout=output_redirect, + preexec_fn=os.fchdir(fd)) #change working directory pid = p.pid self.my_logger.debug(" BitTorrentClientRun: pid = " + str(pid)) diff --git a/autorun/server/HrktorrentRun.py b/autorun/server/HrktorrentRun.py index 6250476..dfb9e8c 100644 --- a/autorun/server/HrktorrentRun.py +++ b/autorun/server/HrktorrentRun.py @@ -29,9 +29,9 @@ def main(): bt_client_data = { CLIENT: HRKTORRENT, PORT:10350, BASE_DIR:"/home/p2p/p2p-clients/hrktorrent-logging/hrktorrent", - TORRENT: "/home/p2p/p2p-meta/test.torrent", + TORRENT: "/home/p2p/export/torrent-files/himym.torrent", DL_DIR: "/home/p2p/p2p-dld/hrktorrent", - LOG_DIR: "/home/p2p/p2p-dld/hrktorrent", + LOG_DIR: "/home/p2p/p2p-log/hrktorrent", OUT_DIR: "/home/p2p/p2p-log/hrktorrent", OUT_FILE: "test.out", #status messages LOG_FILE: "", #verbose messages -- 2.20.1