aboutsummaryrefslogtreecommitdiff
path: root/rcynic
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2012-03-01 23:39:57 +0000
committerRob Austein <sra@hactrn.net>2012-03-01 23:39:57 +0000
commit38100f81c8958323d947f58133c8c4954925521e (patch)
treeab7553e10447ee5bce67782b21f18afb7596b9b2 /rcynic
parent7d29acdd7ff4e737a66a4bd9d010146cbf6caa95 (diff)
Add seed ratio tweak.
svn path=/trunk/; revision=4383
Diffstat (limited to 'rcynic')
-rw-r--r--rcynic/rpki-torrent.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/rcynic/rpki-torrent.py b/rcynic/rpki-torrent.py
index 9c2057d3..c94be3e3 100644
--- a/rcynic/rpki-torrent.py
+++ b/rcynic/rpki-torrent.py
@@ -69,7 +69,9 @@ class TorrentDoesNotMatchManifest(Exception):
class TorrentNameDoesNotMatchURL(Exception):
"Torrent name doesn't uniquely match a URL."
-debug_config = True
+class CouldNotFindTorrents(Exception):
+ "Could not find torrent(s) with given name(s)."
+
def main():
try:
@@ -77,22 +79,25 @@ def main():
if os.isatty(sys.stderr.fileno()):
syslog_flags |= syslog.LOG_PERROR
syslog.openlog("rpki-torrent", syslog_flags)
+
global cfg
cfg = MyConfigParser()
- if debug_config:
- cfg.read("rcynic.conf")
- else:
- cfg.read([os.path.join(dn, fn)
- for fn in ("rcynic.conf", "rpki.conf")
- for dn in ("/var/rcynic/etc", "/usr/local/etc", "/etc")])
+ cfg.read([os.path.join(dn, fn)
+ for fn in ("rcynic.conf", "rpki.conf")
+ for dn in ("/var/rcynic/etc", "/usr/local/etc", "/etc")])
+
if cfg.act_as_generator:
generator_main()
+
elif all(v in os.environ for v in tr_env_vars):
torrent_completion_main()
+
elif not any(v in os.environ for v in tr_env_vars):
cronjob_main()
+
else:
raise InconsistentEnvironment
+
except Exception, e:
for line in traceback.format_exc().splitlines():
syslog.syslog(line)
@@ -146,12 +151,17 @@ def generator_main():
syslog.syslog("Generating manifest")
manifest = create_manifest(download_dir, z.torrent_name)
- # We might be able to use client.add_url() here instead, check later if we care.
syslog.syslog("Loading %s" % torrent_file)
f = open(torrent_file, "rb")
client.add(base64.b64encode(f.read()))
f.close()
+ try:
+ client.change(client.find_torrents(z.torrent_name),
+ seedRatioMode = 2) # 2 = no limit -- see .change()
+ except CouldNotFindTorrents:
+ syslog.syslog("Couldn't tweak seedRatioMode for torrent, blundering onwards")
+
syslog.syslog("Creating upload connection")
ssh = paramiko.Transport((cfg.sftp_host, cfg.sftp_port))
ssh.connect(
@@ -475,14 +485,27 @@ class TransmissionClient(transmissionrpc.client.Client):
Extension of transmissionrpc.client.Client.
"""
- def remove_torrents(self, name):
+ def find_torrents(self, *name):
"""
- Remove any torrents with the given name. In theory there should
- never be more than one, but it doesn't cost much to check.
+ Find torrents with given name(s), return id(s).
"""
- ids = [i for i, t in self.list().iteritems() if t.name == name]
- if ids:
+ result = [i for i, t in self.list().itervalues() if t.name in names]
+ if not result:
+ raise CouldNotFindTorrents
+ return result
+
+
+ def remove_torrents(self, *names):
+ """
+ Remove any torrents with the given name(s).
+ """
+
+ try:
+ ids = self.find_torrents(*names)
+ except CouldNotFindTorrents:
+ pass
+ else:
syslog.syslog("Removing torrent%s %s (%s)" % (
"" if len(ids) == 1 else "s", name, ", ".join("#%s" % i for i in ids)))
self.remove(ids)