diff options
author | Rob Austein <sra@hactrn.net> | 2014-05-31 18:32:19 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2014-05-31 18:32:19 +0000 |
commit | a7cad7f4aab21d48eb783935dfabb9859bcc4f37 (patch) | |
tree | fa8ec4816cfbef4bb3edf01319fe4b7db9b3a73b /rp/rcynic | |
parent | 61309aa7e3c4d8abb6b7e78c979c851f59a70fc4 (diff) |
Still more PyLint.
svn path=/trunk/; revision=5856
Diffstat (limited to 'rp/rcynic')
-rwxr-xr-x | rp/rcynic/rcynic-cron | 8 | ||||
-rwxr-xr-x | rp/rcynic/rcynic-html | 53 | ||||
-rwxr-xr-x | rp/rcynic/rcynic-svn | 27 | ||||
-rwxr-xr-x | rp/rcynic/rcynic-text | 8 | ||||
-rw-r--r-- | rp/rcynic/rpki-torrent.py | 48 | ||||
-rwxr-xr-x | rp/rcynic/validation_status | 6 |
6 files changed, 81 insertions, 69 deletions
diff --git a/rp/rcynic/rcynic-cron b/rp/rcynic/rcynic-cron index d56d706f..53bfea9f 100755 --- a/rp/rcynic/rcynic-cron +++ b/rp/rcynic/rcynic-cron @@ -1,14 +1,14 @@ #!/usr/bin/env python # # $Id$ -# +# # Copyright (C) 2014 Dragon Research Labs ("DRL") # Portions copyright (C) 2013 Internet Systems Consortium ("ISC") -# +# # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notices and this permission notice appear in all copies. -# +# # THE SOFTWARE IS PROVIDED "AS IS" AND DRL AND ISC DISCLAIM ALL # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL OR @@ -96,7 +96,7 @@ else: run(os.path.join(rpki.autoconf.bindir, "rcynic"), "-c", os.path.join(rpki.autoconf.sysconfdir, "rcynic.conf")) run(os.path.join(rpki.autoconf.bindir, "rpki-rtr"), - "cronjob", + "cronjob", os.path.join(rpki.autoconf.RCYNIC_DIR, "data/authenticated"), cwd = os.path.join(rpki.autoconf.RCYNIC_DIR, "rpki-rtr")) diff --git a/rp/rcynic/rcynic-html b/rp/rcynic/rcynic-html index f0a3b574..ef566440 100755 --- a/rp/rcynic/rcynic-html +++ b/rp/rcynic/rcynic-html @@ -1,14 +1,14 @@ #!/usr/bin/env python # # $Id$ -# +# # Copyright (C) 2013--2014 Dragon Research Labs ("DRL") # Portions copyright (C) 2009--2012 Internet Systems Consortium ("ISC") -# +# # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notices and this permission notice appear in all copies. -# +# # THE SOFTWARE IS PROVIDED "AS IS" AND DRL AND ISC DISCLAIM ALL # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL OR @@ -134,7 +134,7 @@ class Validation_Status(object): @property def is_backup(self): return self.generation == "backup" - + @property def is_problem(self): return self.label.mood != "good" @@ -156,7 +156,7 @@ class Validation_Status(object): return not self.label.code.startswith("rsync_transfer_") class Problem_Mixin(object): - + @property def connection_problems(self): result = [v for v in self.validation_status if v.is_connection_problem] @@ -246,9 +246,9 @@ class Host(Problem_Mixin): # differently to indicate how succesful transfer was. Intent is # that exactly one of these be defined for every value in elapsed. - "CDEF:success=failed,UNKN,elapsed,IF", - "CDEF:failure=connections,1,EQ,failed,*,elapsed,UNKN,IF", - "CDEF:partial=connections,1,NE,failed,*,elapsed,UNKN,IF", + r"CDEF:success=failed,UNKN,elapsed,IF", + r"CDEF:failure=connections,1,EQ,failed,*,elapsed,UNKN,IF", + r"CDEF:partial=connections,1,NE,failed,*,elapsed,UNKN,IF", # Show connection timing first, as color-coded semi-transparent # areas with opaque borders. Intent is to make the colors stand @@ -256,27 +256,27 @@ class Host(Problem_Mixin): # handled via an alpha channel (fourth octet of color code). We # draw this stuff first so that later lines can overwrite it. - "AREA:success#00FF0080:Sync time (success)", - "AREA:partial#FFA50080:Sync time (partial failure)", - "AREA:failure#FF000080:Sync time (total failure)", + r"AREA:success#00FF0080:Sync time (success)", + r"AREA:partial#FFA50080:Sync time (partial failure)", + r"AREA:failure#FF000080:Sync time (total failure)", - "LINE1:success#00FF00", # Green - "LINE1:partial#FFA500", # Orange - "LINE1:failure#FF0000", # Red + r"LINE1:success#00FF00", # Green + r"LINE1:partial#FFA500", # Orange + r"LINE1:failure#FF0000", # Red # Now show object counts, as a simple black line. - "LINE1:objects#000000:Objects", # Black + r"LINE1:objects#000000:Objects", # Black # Add averages over period to chart legend. - "VDEF:avg_elapsed=elapsed,AVERAGE", - "VDEF:avg_connections=connections,AVERAGE", - "VDEF:avg_objects=objects,AVERAGE", - "COMMENT:\j", - "GPRINT:avg_elapsed:Average sync time (seconds)\: %5.2lf", - "GPRINT:avg_connections:Average connection count\: %5.2lf", - "GPRINT:avg_objects:Average object count\: %5.2lf" ) + r"VDEF:avg_elapsed=elapsed,AVERAGE", + r"VDEF:avg_connections=connections,AVERAGE", + r"VDEF:avg_objects=objects,AVERAGE", + r"COMMENT:\j", + r"GPRINT:avg_elapsed:Average sync time (seconds)\: %5.2lf", + r"GPRINT:avg_connections:Average connection count\: %5.2lf", + r"GPRINT:avg_objects:Average object count\: %5.2lf" ) graph_periods = (("week", "-1w"), ("month", "-31d"), @@ -303,6 +303,7 @@ class Host(Problem_Mixin): "%s:%s" % (self.timestamp, ":".join(str(v) for v in self.field_values))]) def rrd_graph(self, html): + # pylint: disable=W0622 filebase = os.path.join(args.output_directory, self.hostname) formats = [format for format in ("png", "svg", "eps") if getattr(args, format + "_width") and getattr(args, format + "_height")] @@ -331,7 +332,7 @@ class Host(Problem_Mixin): svg_html.BodyElement("img", src = "%s_%s.svg" % (self.hostname, period)) svg_html.close() - + class Session(Problem_Mixin): def __init__(self): @@ -479,7 +480,7 @@ class HTML(object): self.filename = os.path.join(args.output_directory, filebase + ".html") self.html = Element("html") - self.html.append(Comment(" Generators:\n" + + self.html.append(Comment(" Generators:\n" + " " + session.rcynic_version + "\n" + " $Id$\n")) self.head = SubElement(self.html, "head") @@ -546,7 +547,7 @@ class HTML(object): td.text = str(count) return table - def object_count_table(self, session): + def object_count_table(self, session): # pylint: disable=W0621 table = self.BodyElement("table", rules = "all", border = "1") thead = SubElement(table, "thead") tbody = SubElement(table, "tbody") @@ -595,7 +596,7 @@ class HTML(object): def main(): global session - + os.putenv("TZ", "UTC") time.tzset() diff --git a/rp/rcynic/rcynic-svn b/rp/rcynic/rcynic-svn index c667ec4a..28b24672 100755 --- a/rp/rcynic/rcynic-svn +++ b/rp/rcynic/rcynic-svn @@ -24,7 +24,6 @@ import subprocess import argparse import datetime import fcntl -import glob import os try: @@ -43,34 +42,34 @@ mime_types = ( ("gbr", "application/rpki-ghostbusters")) -def run(*cmd, **kwargs): +def run(*argv, **kwargs): """ Run a program, displaying timing data when appropriate. """ - t = datetime.datetime.utcnow() - subprocess.check_call(cmd, **kwargs) + _t0 = datetime.datetime.utcnow() + subprocess.check_call(argv, **kwargs) if args.show_timing: - now = datetime.datetime.utcnow() - print now, (now - t), " ".join(cmd) + _t1 = datetime.datetime.utcnow() + print _t1, (_t1 - _t0), " ".join(argv) -def runxml(*cmd): +def runxml(*argv): """ Run a program which produces XML output, displaying timing data when appropriate and returning an ElementTree constructed from the program's output. """ - t = datetime.datetime.utcnow() - p = subprocess.Popen(cmd, stdout = subprocess.PIPE) + _t0 = datetime.datetime.utcnow() + p = subprocess.Popen(argv, stdout = subprocess.PIPE) x = ElementTree(file = p.stdout) s = p.wait() if s: - raise subprocess.CalledProcessError(s, cmd[0]) + raise subprocess.CalledProcessError(s, argv[0]) if args.show_timing: - now = datetime.datetime.utcnow() - print now, (now - t), " ".join(cmd) + _t1 = datetime.datetime.utcnow() + print _t1, (_t1 - _t0), " ".join(argv) return x @@ -188,5 +187,5 @@ run("svn", "commit", "--quiet", "--message", "Auto update.", args.working_direct run("svn", "update", "--quiet", args.working_directory) if args.show_timing: - now = datetime.datetime.utcnow() - print now, now - t0, "total runtime" + t1 = datetime.datetime.utcnow() + print t1, t1 - t0, "total runtime" diff --git a/rp/rcynic/rcynic-text b/rp/rcynic/rcynic-text index c837e88b..db4126ce 100755 --- a/rp/rcynic/rcynic-text +++ b/rp/rcynic/rcynic-text @@ -1,13 +1,13 @@ #!/usr/bin/env python # # $Id$ -# +# # Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") -# +# # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. -# +# # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, @@ -88,7 +88,7 @@ class Session(object): hostnames = sorted(hostname for hostname in self.hosts if hostname is not None) hostwidth = max(len(hostname) for hostname in hostnames + ["Hostname"]) separator = "+-%s-+-%s-+" % ( - "-" * hostwidth, + "-" * hostwidth, "-+-".join("-" * label.width for label in visible)) print separator for i in xrange(max(len(label.lines) for label in visible)): 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) diff --git a/rp/rcynic/validation_status b/rp/rcynic/validation_status index 1ff17e75..a3ee36f1 100755 --- a/rp/rcynic/validation_status +++ b/rp/rcynic/validation_status @@ -1,13 +1,13 @@ #!/usr/bin/env python # # $Id$ -# +# # Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") -# +# # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. -# +# # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, |