import shlex
import logging
from string import Template
+from Util import *
class BitTorrentClientRun:
my_logger = None
def run_client(self, command, client):
try:
+
+ log_redirect = None
+ p = None
+ pid = None
+
# split command
args = shlex.split(command)
# remove redirectation parameters
#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))
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