aboutsummaryrefslogtreecommitdiff
path: root/rp/rcynic/rpki-torrent.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2014-05-31 18:32:19 +0000
committerRob Austein <sra@hactrn.net>2014-05-31 18:32:19 +0000
commita7cad7f4aab21d48eb783935dfabb9859bcc4f37 (patch)
treefa8ec4816cfbef4bb3edf01319fe4b7db9b3a73b /rp/rcynic/rpki-torrent.py
parent61309aa7e3c4d8abb6b7e78c979c851f59a70fc4 (diff)
Still more PyLint.
svn path=/trunk/; revision=5856
Diffstat (limited to 'rp/rcynic/rpki-torrent.py')
-rw-r--r--rp/rcynic/rpki-torrent.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/rp/rcynic/rpki-torrent.py b/rp/rcynic/rpki-torrent.py
index c823aad9..2c6aa64d 100644
--- a/rp/rcynic/rpki-torrent.py
+++ b/rp/rcynic/rpki-torrent.py
@@ -75,16 +75,29 @@ class CouldNotFindTorrents(Exception):
class UseTheSourceLuke(Exception):
"Use The Source, Luke."
+cfg = None
+
def main():
try:
- syslog_flags = syslog.LOG_PID;
+ syslog_flags = syslog.LOG_PID
if os.isatty(sys.stderr.fileno()):
syslog_flags |= syslog.LOG_PERROR
syslog.openlog("rpki-torrent", syslog_flags)
+ # If I seriously expected this script to get a lot of further use,
+ # I might rewrite this using subparsers, but it'd be a bit tricky
+ # as argparse doesn't support making the subparser argument
+ # optional and transmission gives no sane way to provide arguments
+ # when running a completion script. So, for the moment, let's
+ # just fix the bugs accidently introduced while converting the
+ # universe to argparse without making any radical changes to the
+ # program structure here, even if the result looks kind of klunky.
+
parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument("-c", "--config",
help = "configuration file")
+ parser.add_argument("action", choices = ("poll", "generate", "mirror"), nargs = "?",
+ help = "action to take")
args = parser.parse_args()
global cfg
@@ -95,22 +108,21 @@ def main():
for dn in ("/var/rcynic/etc", "/usr/local/etc", "/etc")])
if cfg.act_as_generator:
- if len(argv) == 1 and argv[0] == "generate":
+ if args.action == "generate":
generator_main()
- elif len(argv) == 1 and argv[0] == "mirror":
+ elif args.action == "mirror":
mirror_main()
else:
raise UseTheSourceLuke
-
else:
- if len(argv) == 0 and all(v in os.environ for v in tr_env_vars):
+ if args.action is None and all(v in os.environ for v in tr_env_vars):
torrent_completion_main()
- elif len(argv) == 1 and argv[0] == "poll":
+ elif args.action == "poll":
poll_main()
else:
raise UseTheSourceLuke
- except Exception, e:
+ except:
for line in traceback.format_exc().splitlines():
syslog.syslog(line)
sys.exit(1)
@@ -126,7 +138,7 @@ def generator_main():
self._log(paramiko.common.DEBUG, 'atomic_rename(%r, %r)' % (oldpath, newpath))
self._request(paramiko.sftp.CMD_EXTENDED, "posix-rename@openssh.com", oldpath, newpath)
- z = ZipFile(url = cfg.generate_url, dir = cfg.zip_dir)
+ z = ZipFile(url = cfg.generate_url, dn = cfg.zip_dir)
client = TransmissionClient()
client.remove_torrents(z.torrent_name)
@@ -147,7 +159,7 @@ def generator_main():
except OSError, e:
if e.errno != errno.ENOENT:
raise
- ignore_output_for_now = subprocess.check_output(
+ ignore_output_for_now = subprocess.check_output( # pylint: disable=W0612
(cfg.mktorrent_prog,
"-a", cfg.tracker_url,
"-c", "RPKI unauthenticated data snapshot generated by rpki-torrent",
@@ -212,7 +224,7 @@ def mirror_main():
for zip_url in cfg.zip_urls:
if zip_url != cfg.generate_url:
- z = ZipFile(url = zip_url, dir = cfg.zip_dir, ta = cfg.zip_ta)
+ z = ZipFile(url = zip_url, dn = cfg.zip_dir, ta = cfg.zip_ta)
if z.fetch():
client.remove_torrents(z.torrent_name)
syslog.syslog("Mirroring torrent %s" % z.torrent_name)
@@ -226,7 +238,7 @@ def mirror_main():
def poll_main():
for zip_url in cfg.zip_urls:
- z = ZipFile(url = zip_url, dir = cfg.zip_dir, ta = cfg.zip_ta)
+ z = ZipFile(url = zip_url, dn = cfg.zip_dir, ta = cfg.zip_ta)
client = TransmissionClient()
if z.fetch():
@@ -242,7 +254,7 @@ def torrent_completion_main():
torrent_name = os.getenv("TR_TORRENT_NAME")
torrent_id = int(os.getenv("TR_TORRENT_ID"))
- z = ZipFile(url = cfg.find_url(torrent_name), dir = cfg.zip_dir, ta = cfg.zip_ta)
+ z = ZipFile(url = cfg.find_url(torrent_name), dn = cfg.zip_dir, ta = cfg.zip_ta)
client = TransmissionClient()
torrent = client.info([torrent_id]).popitem()[1]
@@ -324,12 +336,12 @@ class ZipFile(object):
may first need to be fetched via HTTPS.
"""
- def __init__(self, url, dir, ta = None, verbose = True):
+ def __init__(self, url, dn, ta = None, verbose = True):
self.url = url
- self.dir = dir
+ self.dir = dn
self.ta = ta
self.verbose = verbose
- self.filename = os.path.join(dir, os.path.basename(url))
+ self.filename = os.path.join(dn, os.path.basename(url))
self.changed = False
self.zf = None
self.peercert = None
@@ -401,7 +413,7 @@ class ZipFile(object):
tempname = self.filename + ".new"
f = open(tempname, "wb")
n = int(r.info()["Content-Length"])
- for i in xrange(0, n - bufsize, bufsize):
+ for i in xrange(0, n - bufsize, bufsize): # pylint: disable=W0612
f.write(r.read(bufsize))
f.write(r.read())
f.close()
@@ -510,7 +522,7 @@ def create_manifest(topdir, torrent_name):
result = {}
topdir = os.path.abspath(topdir)
- for dirpath, dirnames, filenames in os.walk(os.path.join(topdir, torrent_name)):
+ for dirpath, dirnames, filenames in os.walk(os.path.join(topdir, torrent_name)): # pylint: disable=W0612
for filename in filenames:
filename = os.path.join(dirpath, filename)
f = open(filename, "rb")
@@ -697,7 +709,7 @@ class MyConfigParser(ConfigParser.RawConfigParser):
yield getter(self.rpki_torrent_section, name)
name += "."
names = [i for i in self.options(self.rpki_torrent_section) if i.startswith(name) and i[len(name):].isdigit()]
- names.sort(key = lambda s: int(s[len(name):]))
+ names.sort(key = lambda s: int(s[len(name):])) # pylint: disable=W0631
for name in names:
yield getter(self.rpki_torrent_section, name)