From b5ad5d0693834ab7220cbaed99fdd7e6a87bfd59 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 29 Jan 2010 11:45:25 +0200 Subject: [PATCH] updated BitTorrent client start Python --- scripts/start-clients/BitTorrentClientRun.py | 140 ++++++------------- scripts/start-clients/TransmissionRun.py | 16 +-- 2 files changed, 54 insertions(+), 102 deletions(-) diff --git a/scripts/start-clients/BitTorrentClientRun.py b/scripts/start-clients/BitTorrentClientRun.py index eca5bde..bb96196 100644 --- a/scripts/start-clients/BitTorrentClientRun.py +++ b/scripts/start-clients/BitTorrentClientRun.py @@ -5,104 +5,55 @@ 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro """ -""" - - - src/transmission-cli - - - - - -u - -d - -p - -l - -o - -""" - -""" - - 141.85.224.201 - 10150 - 172.30.10.0 - 10150 - 10122 - - - /home/p2p/p2p-clients/tribler/ - - - /home/p2p/p2p-clients/libtorrent/ - - - /home/p2p/p2p-clients/transmission/ - - - -""" - -""" - - 1 - triber - 512 - 256 - 9999 - /this/dir - /this/dir - - - - - - - - - -""" - 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() diff --git a/scripts/start-clients/TransmissionRun.py b/scripts/start-clients/TransmissionRun.py index fb389e8..c6ba26e 100644 --- a/scripts/start-clients/TransmissionRun.py +++ b/scripts/start-clients/TransmissionRun.py @@ -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() -- 2.20.1