autorun: tested Hrktorrent with logging
authorP2P-Next <p2p-next@cs.pub.ro>
Fri, 21 May 2010 15:21:55 +0000 (18:21 +0300)
committerP2P-Next <p2p-next@cs.pub.ro>
Fri, 21 May 2010 15:21:55 +0000 (18:21 +0300)
autorun/server/BitTorrentClientRun.py
autorun/server/Client.py
autorun/server/HrktorrentRun.py
autorun/server/start-server

index 7115372..018a1d2 100644 (file)
@@ -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():
index a4d6c1a..fd4d1fe 100644 (file)
@@ -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",
index 540f494..8debcf8 100644 (file)
@@ -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__":
index 18c6618..d4032f6 100755 (executable)
@@ -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