server: solved libtorrent's verbose logging dir problem
authorAdriana Draghici <adriana.draghici@cti.pub.ro>
Mon, 28 Jun 2010 11:56:26 +0000 (14:56 +0300)
committerAdriana Draghici <adriana.draghici@cti.pub.ro>
Mon, 28 Jun 2010 11:56:26 +0000 (14:56 +0300)
autorun/server/BitTorrentClientRun.py
autorun/server/HrktorrentRun.py

index af8245f..d8612d5 100644 (file)
@@ -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))
index 6250476..dfb9e8c 100644 (file)
@@ -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