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)
print self.simple_run_command
print self.logging_run_command
-
+
def run_client(self, command):
try:
# split command
#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:
if pid != None:
os.kill(int_pid, signal.SIGKILL) # kill generates zombies
os.wait()
- raise Exception
+
+ raise
def main():
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",
import sys
import os.path
from BitTorrentClientRun import BitTorrentClientRun
+from Util import *
DEBUG = False
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__":
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