updated BitTorrent client start Python
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 29 Jan 2010 09:45:25 +0000 (11:45 +0200)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 29 Jan 2010 09:45:29 +0000 (11:45 +0200)
scripts/start-clients/BitTorrentClientRun.py
scripts/start-clients/TransmissionRun.py

index eca5bde..bb96196 100644 (file)
  2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
 """
 
-"""
-    <client id="transmission">
-       <run type="executable">
-           <file>src/transmission-cli</file>
-           <interpreter></interpreter>
-           <prefix></prefix>
-           <suffix></suffix>
-       </run>
-       <upload_limit_option>-u</upload_limit_option>
-       <download_limit_option>-d</download_limit_option>
-       <port_option>-p</port_option>
-       <logging_dir_option>-l</logging_dir_option>
-       <download_dir_option>-o</download_dir_option>
-    </client>
-"""
-
-"""
-    <node id="1">
-       <public_address>141.85.224.201</public_address>
-       <public_port>10150</public_port>
-       <private_address>172.30.10.0</private_address>
-       <private_port>10150</private_port>
-       <ssh_port>10122</ssh_port>
-       <clients>
-           <client id="tribler">
-               <base>/home/p2p/p2p-clients/tribler/</base>
-           </client>
-           <client id="libtorrent">
-               <base>/home/p2p/p2p-clients/libtorrent/</base>
-           </client>
-           <client id="transmission">
-               <base>/home/p2p/p2p-clients/transmission/</base>
-           </client>
-        </clients>
-    </node>
-"""
-
-"""
-    <instance id="1">
-       <node>1</node>
-       <client>triber</client>
-       <upload_limit>512</upload_limit>
-       <download_limit>256</download_limit>
-       <port>9999</port>
-       <download_dir>/this/dir</download_dir>
-       <logging_dir>/this/dir</logging_dir>
-       <actions>
-           <action type="start" delay="00:05:00" />
-           <action type="stop" delay="00:10:00" />
-           <action type="start" delay="00:15:00" />
-           <action type="stop" delay="00:20:00" />
-           <action type="start" delay="00:25:00" />
-           <action type="start" delay="end" />
-       </actions>
-    </instance>
-"""
-
 import sys
 import os.path
+from string import Template
 
 DEBUG = False
 
 class BitTorrentClientRun:
-       def __init__(self, base_path):
-               self.base_path = base_path
-               pass
-
-       def config_client(self, simple_run_expr, logging_run_expr):
-               self.simple_run_expr = simple_run_expr
-               self.logging_run_expr = logging_run_expr
-
-       def config_client2(self, prefix, suffix, file, run_type,
-                       interpreter, download_dir_option,
-                       logging_dir_option, port_option):
-               self.prefix = prefix
-               self.suffix = suffix
-               self.file = file
-               self.run_type = run_type
-               self.interpreter = interpreter
-               self.download_dir_option = download_dir_option
-               self.logging_dir_option = logging_dir_option
-               self.port_option = port_option
-
-       def config_run(self, download_dir, logging_dir, port):
-               self.download_dir = download_dir
-               self.logging_dir = logging_dir
-               self.port = port
-
-       def start2(self):
-               self.command = "%s %s %s/%s %s %s %s %s %s %d %s" % (self.prefix, self.interpreter, self.base_path, self.file, self.download_dir_option, self.download_dir, self.logging_dir_option, self.logging_dir, self.port_option, self.port, self.suffix)
-               print self.command
-
-       def start(self):
-               self.simple_run_command = self.simple_run_expr.replace("$base_pat", self.base_path).replace("$download_dir", self.download_dir).replace("$logging_dir", self.logging).replace("$port", self.port)
-               self.logging_run_command = self.logging_run_expr.replace("$base_pat", self.base_path).replace("$download_dir", self.download_dir).replace("$logging", self.logging).replace("$port", self.port)
+    def __init__(self, base_path, simple_run_expr, logging_run_expr):
+        self.base_path = base_path
+        self.simple_run_expr = simple_run_expr
+        self.logging_run_expr = logging_run_expr
+
+    def config_run(self, download_dir, output_dir, output_file, log_dir, log_file, port, torrent_file):
+        self.download_dir = download_dir
+        self.output_dir = output_dir
+        self.output_file = output_file
+        self.log_dir = log_dir
+        self.log_file = log_file
+        self.port = port
+        self.torrent_file = torrent_file
+
+    def start(self):
+        t = Template(self.simple_run_expr)
+        self.simple_run_command = t.substitute(
+                base_path = self.base_path,
+                download_dir = self.download_dir,
+                output_dir = self.output_dir,
+                output_file = self.output_file,
+                log_dir = self.log_dir,
+                log_file = self.log_file,
+                port = str(self.port),
+                torrent_file = self.torrent_file
+                )
+
+        t = Template(self.logging_run_expr)
+        self.logging_run_command = t.substitute(
+                base_path = self.base_path,
+                download_dir = self.download_dir,
+                output_dir = self.output_dir,
+                output_file = self.output_file,
+                log_dir = self.log_dir,
+                log_file = self.log_file,
+                port = str(self.port),
+                torrent_file = self.torrent_file
+                )
+
+        print self.simple_run_command
+        print self.logging_run_command
 
-               print self.simple_run_command
-               print self.logging_run_command
 
 def main():
 
@@ -110,9 +61,10 @@ def main():
     Test case
     """
 
-    btcr = BitTorrentClientRun("/home/p2p/p2p-clients/transmission/")
-    btcr.config_client("", "", "cli/transmissioncli", "executable", "", "--download-dir", "", "--port")
-    btcr.config_run("/home/p2p/p2p-dld/transmission/", "/home/p2p/p2p-log/transmission/", 10150)
+    btcr = BitTorrentClientRun("/home/p2p/p2p-clients/transmission",
+            "$base_path/cli/transmissioncli --download-dir $download_dir --port $port $torrent_file > $output_dir/$output_file",
+            "TR_DEBUG=2 $base_path/cli/transmissioncli --download-dir $download_dir --port $port $torrent_file 2> $log_dir/$log_file > $output_dir/$output_file")
+    btcr.config_run("/home/p2p/p2p-dld/transmission", "/home/p2p/p2p-log/transmission", "transmission-fedora.out", "/home/p2p/p2p-log/transmission", "transmission-fedora.log", 10150, "/home/p2p/p2p-meta/fedora.torrent")
     btcr.start()
 
 
index fb389e8..c6ba26e 100644 (file)
@@ -7,16 +7,16 @@
 
 import sys
 import os.path
-import BitTorrentClientRun
+from BitTorrentClientRun import BitTorrentClientRun
 
 DEBUG = False
 
+
 class TransmissionRun(BitTorrentClientRun):
-       def __init__(self, base_path):
-               self.base_path = base_path
-               simple_run_expr = "$base_path/cli/transmissioncli --download-dir $download_dir --port $port $torrent_file > $output_dir/$out_file"
-               logging_run_expr = "TR_DEBUG=2 $base_path/cli/transmissioncli --download-dir $download_dir --port $port $torrent_file 2> $logging_dir/$log_file > $output_dir/$out_file"
-               BitTorrentClientRun.config_client(simple_run_expr, logging_run_expr)
+    def __init__(self, base_path):
+        BitTorrentClientRun.__init__(self, base_path,
+                "$base_path/cli/transmissioncli --download-dir $download_dir --port $port $torrent_file > $output_dir/$output_file",
+                "TR_DEBUG=2 $base_path/cli/transmissioncli --download-dir $download_dir --port $port $torrent_file 2> $log_dir/$log_file > $output_dir/$output_file")
 
 
 def main():
@@ -25,8 +25,8 @@ def main():
     Test case
     """
 
-    tr = TransmissionRun("/home/p2p/p2p-clients/transmission/")
-    tr.config_run("/home/p2p/p2p-dld/transmission/", "/home/p2p/p2p-log/transmission/", 10150)
+    tr = TransmissionRun("/home/p2p/p2p-clients/transmission")
+    tr.config_run("/home/p2p/p2p-dld/transmission", "/home/p2p/p2p-log/transmission", "transmission-fedora.out", "/home/p2p/p2p-log/transmission", "transmission-fedora.log", 10150, "/home/p2p/p2p-meta/fedora.torrent")
     tr.start()