aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildtools/build-ubuntu-ports.py75
-rw-r--r--buildtools/pull-doc-from-wiki.py114
-rw-r--r--rcynic/rcynic-html.py153
-rw-r--r--rcynic/rpki-torrent.py55
4 files changed, 165 insertions, 232 deletions
diff --git a/buildtools/build-ubuntu-ports.py b/buildtools/build-ubuntu-ports.py
index bb60af8a..8ee2efcc 100644
--- a/buildtools/build-ubuntu-ports.py
+++ b/buildtools/build-ubuntu-ports.py
@@ -1,56 +1,43 @@
-# Set up for an Ubuntu package build.
-#
-# This is a script because we need to set the changelog, and some day
-# we may need to do something about filtering specific files so we can
-# use the same skeleton for both Ubuntu and Debian builds without
-# requiring them to be identical.
-#
-# For now, though, this just copies the debian skeleton and creates a
-# changelog.
-#
# $Id$
#
-# Copyright (C) 2013 Internet Systems Consortium ("ISC")
-#
+# 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 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,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# 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
+# ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
+"""
+Set up for a Debian or Ubuntu package build.
+
+This is a script because we need to set the changelog, and some day
+we may need to do something about filtering specific files so we can
+use the same skeleton for both Ubuntu and Debian builds without
+requiring them to be identical.
+
+For now, though, this just copies the debian skeleton and creates a
+changelog.
+"""
+
import subprocess
-import getopt
+import argparse
import shutil
import sys
import os
-def usage(status):
- f = sys.stderr if status else sys.stdout
- f.write("Usage: %s [--debuild] [--debi]\n" % sys.argv[0])
- sys.exit(status)
-
-debuild = False
-debi = False
-
-try:
- opts, argv = getopt.getopt(sys.argv[1:], "-bih?", ["debuild", "debi", "help"])
-except getopt.GetoptError:
- usage(1)
-for o, a in opts:
- if o in ("-h", "-?", "--help"):
- usage(0)
- elif o in ("-b", "--debuild"):
- debuild = not debuild
- elif o in ("-i", "--debi"):
- debi = not debi
-if argv:
- usage(1)
+parser = argparse.ArgumentParser(description = __doc__)
+parser.add_argument("-b", "--debuild", action = "store_true", help = "run debuild")
+parser.add_argument("-i", "--debi", action = "store_true", help = "run debi")
+args = parser.parse_args()
version = "0." + subprocess.check_output(("svnversion", "-c")).strip().split(":")[-1]
@@ -72,8 +59,8 @@ subprocess.check_call(("dch", "--create", "--package", "rpki", "--newversion",
TZ = "UTC",
DEBEMAIL = "APT Builder Robot <aptbot@rpki.net>"))
-if debuild or debi:
+if args.debuild or args.debi:
subprocess.check_call(("debuild", "-us", "-uc"))
-if debi:
+if args.debi:
subprocess.check_call(("sudo", "debi", "--with-depends"))
diff --git a/buildtools/pull-doc-from-wiki.py b/buildtools/pull-doc-from-wiki.py
index a9e57d9a..e3b61b53 100644
--- a/buildtools/pull-doc-from-wiki.py
+++ b/buildtools/pull-doc-from-wiki.py
@@ -1,4 +1,20 @@
-#!/usr/bin/env python
+# $Id$
+#
+# Copyright (C) 2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 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
+# ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
"""
Pull HTML pages from a Trac Wiki, feed the useful bits to htmldoc and
@@ -7,34 +23,18 @@ html2text to generate PDF and flat text documentation.
Assumes you're using the TracNav plugin for the Wiki pages, and uses
the same list as the TracNav plugin does to determine the set of pages
to convert and the order in which they appear in the PDF file.
-
-Most of the work of massaging the HTML is done using XSL transforms,
-because the template-driven style makes that easy. There's probably
-some clever way to use lxml's XPath code to do the same thing in a
-more pythonic way with ElementTrees, but I already had the XSL
-transforms and there's a point of diminishing returns on this sort of
-thing.
"""
-# $Id$
-#
-# Copyright (C) 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 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,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
+# Most of the work of massaging the HTML is done using XSL transforms,
+# because the template-driven style makes that easy. There's probably
+# some clever way to use lxml's XPath code to do the same thing in a
+# more pythonic way with ElementTrees, but I already had the XSL
+# transforms and there's a point of diminishing returns on this sort of
+# thing.
import sys
import os
-import getopt
+import argparse
import lxml.etree
import urllib
import urlparse
@@ -45,45 +45,33 @@ import tempfile
def main():
- base = "https://trac.rpki.net"
- toc = base + "/wiki/doc/RPKI/TOC"
- pdf = "manual.pdf"
- dir = "."
- h2trc = os.path.join(os.path.dirname(sys.argv[0]), "html2textrc")
-
- options = ["base_url=", "directory=", "help", "html2textrc", "pdf_file=", "toc="]
-
- def usage(msg = 0):
- sys.stderr.write("Usage: %s %s\n" % (
- sys.argv[0], " ".join("[--%s value]" % o[:-1] if o.endswith("=") else "[--%s]" % o
- for o in options)))
- sys.stderr.write(__doc__)
- sys.exit(msg)
-
- opts, argv = getopt.getopt(sys.argv[1:], "b:d:hp:r:t:?", options)
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- usage()
- elif o in ("-b", "--base_url"):
- base = a
- elif o in ("-d", "--directory"):
- dir = a
- elif o in ("-p", "--pdf_file"):
- pdf = a
- elif o in ("-r", "--html2textrc"):
- h2trc = a
- elif o in ("-t", "--toc"):
- toc = a
- if argv:
- usage("Unexpected arguments %s" % argv)
-
- urls = str(xsl_get_toc(lxml.etree.parse(urllib.urlopen(toc)).getroot(),
- basename = repr(base))).splitlines()
+ base = "https://trac.rpki.net"
+
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-b", "--base_url",
+ default = base,
+ help = "base URL for documentation web site")
+ parser.add_argument("-t", "--toc",
+ default = base + "/wiki/doc/RPKI/TOC",
+ help = "table of contents URL")
+ parser.add_argument("-d", "--directory",
+ default = ".",
+ help = "output directory")
+ parser.add_argument("-p", "--pdf_file",
+ default = "manual.pdf",
+ help = "output PDF file")
+ parser.add_argument("-r", "--html2textrc",
+ default = os.path.join(os.path.dirname(sys.argv[0]), "html2textrc"),
+ help = "html2textrc rules file")
+ args = parser.parse_args()
+
+ urls = str(xsl_get_toc(lxml.etree.parse(urllib.urlopen(args.toc)).getroot(),
+ basename = repr(args.base_url))).splitlines()
assert all(urlparse.urlparse(url).path.startswith("/wiki/") for url in urls)
htmldoc = subprocess.Popen(
- ("htmldoc", "--book", "--title", "--outfile", pdf, "--format", "pdf",
+ ("htmldoc", "--book", "--title", "--outfile", args.pdf_file, "--format", "pdf",
"--firstpage", "p1", "--size", "Universal", "--no-duplex",
"--fontsize", "11.0", "--fontspacing", "1.1", "--headfootsize", "11.0",
"--headingfont", "Helvetica", "--bodyfont", "Times", "--headfootfont", "Helvetica-Oblique",
@@ -96,7 +84,7 @@ def main():
for url in urls:
path = urlparse.urlparse(url).path
page = xsl_get_page(lxml.etree.parse(urllib.urlopen(url)).getroot(),
- basename = repr(base),
+ basename = repr(args.base_url),
path = repr(path))
for img in page.xpath("//img | //object | //embed"):
@@ -114,7 +102,7 @@ def main():
page.write(htmldoc.stdin)
- html2text = subprocess.Popen(("html2text", "-rcfile", h2trc, "-nobs", "-ascii"),
+ html2text = subprocess.Popen(("html2text", "-rcfile", args.html2textrc, "-nobs", "-ascii"),
stdin = subprocess.PIPE,
stdout = subprocess.PIPE)
page.write(html2text.stdin)
@@ -126,7 +114,7 @@ def main():
while lines and lines[0].isspace():
del lines[0]
- fn = os.path.join(dir, path[len("/wiki/"):].replace("/", "."))
+ fn = os.path.join(args.directory, path[len("/wiki/"):].replace("/", "."))
f = open(fn, "w")
want_blank = False
for line in lines:
@@ -141,7 +129,7 @@ def main():
htmldoc.stdin.close()
htmldoc.wait()
- sys.stderr.write("Wrote %s\n" % pdf)
+ sys.stderr.write("Wrote %s\n" % args.pdf_file)
for png_fn in png_fns:
os.unlink(png_fn)
diff --git a/rcynic/rcynic-html.py b/rcynic/rcynic-html.py
index c7dfcfe2..58e65dde 100644
--- a/rcynic/rcynic-html.py
+++ b/rcynic/rcynic-html.py
@@ -17,13 +17,13 @@
# PERFORMANCE OF THIS SOFTWARE.
"""
-Render rcynic's XML output to basic (X)HTML with some rrdtool graphis.
+Render rcynic's XML output to basic (X)HTML with some rrdtool graphics.
"""
import sys
import urlparse
import os
-import getopt
+import argparse
import time
import subprocess
import copy
@@ -34,81 +34,47 @@ except ImportError:
from xml.etree.ElementTree import (ElementTree, Element, SubElement, Comment)
session = None
-
-opt = {
- "refresh" : 1800,
- "show-problems" : True,
- "show-graphs" : True,
- "show-object-counts" : True,
- "update-rrds" : True,
- "png-height" : 190,
- "png-width" : 1350,
- "svg-height" : 600,
- "svg-width" : 1200,
- "eps-height" : 0,
- "eps-width" : 0 }
-
-try:
- # Set from autoconf
- opt["rrdtool-binary"] = ac_rrdtool_binary
-except NameError:
- # Not set at all
- opt["rrdtool-binary"] = "rrdtool"
-
-def usage(msg = 0):
- f = sys.stderr if msg else sys.stdout
- f.write("Usage: %s %s [options] input_file output_directory\n" % (sys.executable, sys.argv[0]))
- f.write("Options:\n")
- for i in sorted(opt):
- if "_" not in i and not isinstance(opt[i], bool):
- f.write(" --%-30s (%s)\n" % (i + " <value>", opt[i]))
- for i in sorted(opt):
- if "_" not in i and isinstance(opt[i], bool):
- f.write(" --[no-]%-25s (--%s%s)\n" % (i, "" if opt[i] else "no-", i))
- if msg:
- f.write("\n")
- sys.exit(msg)
+args = None
def parse_options():
- opts = ["help"]
- for i in opt:
- if isinstance(opt[i], bool):
- opts.append(i)
- opts.append("no-" + i)
- else:
- opts.append(i + "=")
-
- try:
- opts, argv = getopt.getopt(sys.argv[1:], "h?", opts)
- for o, a in opts:
- if o in ("-?", "-h", "--help"):
- usage(0)
- negated = o.startswith("--no-")
- o = o[5:] if negated else o[2:]
- if isinstance(opt[o], bool):
- opt[o] = not negated
- elif isinstance(opt[o], int):
- opt[o] = int(a)
- else:
- opt[o] = a
- except Exception, e:
- usage("%s: %s" % (e.__class__.__name__, str(e)))
-
- if len(argv) > 2:
- usage("Unexpected arguments")
+ global args
try:
- opt["input_file"] = argv[0]
- opt["output_directory"] = argv[1]
- except IndexError:
- usage("Missing required arguments")
-
- if not os.path.isdir(opt["output_directory"]):
- try:
- os.makedirs(opt["output_directory"])
- except OSError, e:
- sys.exit("Couldn't create output directory: %s" % e)
+ default_rrdtool_binary = ac_rrdtool_binary
+ except NameError:
+ default_rrdtool_binary = "rrdtool"
+
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("--refresh", type = int, default = 1800,
+ help = "refresh interval for generated HTML")
+ parser.add_argument("--hide-problems", action = "store_true",
+ help = "don't generate \"problems\" page")
+ parser.add_argument("--hide-graphs", action = "store_true",
+ help = "don't generate graphs")
+ parser.add_argument("--hide-object-counts", action = "store_true",
+ help = "don't display object counts")
+ parser.add_argument("--dont-update-rrds", action = "store_true",
+ help = "don't add new data to RRD databases")
+ parser.add_argument("--png-height", type = int, default = 190,
+ help = "height of PNG images")
+ parser.add_argument("--png-width", type = int, default = 1350,
+ help = "width of PNG images")
+ parser.add_argument("--svg-height", type = int, default = 600,
+ help = "height of SVG images")
+ parser.add_argument("--svg-width", type = int, default = 1200,
+ help = "width of SVG images")
+ parser.add_argument("--eps-height", type = int, default = 0,
+ help = "height of EPS images")
+ parser.add_argument("--eps-width", type = int, default = 0,
+ help = "width of EPS images")
+ parser.add_argument("--rrdtool-binary", default = default_rrdtool_binary,
+ help = "location of rrdtool binary")
+ parser.add_argument("input_file", type = argparse.FileType("r"),
+ help = "XML input file")
+ parser.add_argument("output_directory",
+ help = "output directory")
+ args = parser.parse_args()
def parse_utc(s):
@@ -321,17 +287,15 @@ class Host(Problem_Mixin):
def rrd_run(self, cmd):
try:
cmd = [str(i) for i in cmd]
- cmd.insert(0, opt["rrdtool-binary"])
+ cmd.insert(0, args.rrdtool_binary)
subprocess.check_call(cmd, stdout = open("/dev/null", "w"))
except OSError, e:
- usage("Problem running %s, perhaps you need to set --rrdtool-binary? (%s)" % (
- opt["rrdtool-binary"], e))
+ sys.exit("Problem running %s, perhaps you need to set --rrdtool-binary? (%s)" % (args.rrdtool_binary, e))
except subprocess.CalledProcessError, e:
- sys.exit("Failure running %s: %s" % (
- opt["rrdtool-binary"], e))
+ sys.exit("Failure running %s: %s" % (args.rrdtool_binary, e))
def rrd_update(self):
- filename = os.path.join(opt["output_directory"], self.hostname) + ".rrd"
+ filename = os.path.join(args.output_directory, self.hostname) + ".rrd"
if not os.path.exists(filename):
cmd = ["create", filename, "--start", self.timestamp - 1, "--step", "3600"]
cmd.extend(self.field_ds_specifiers())
@@ -341,24 +305,24 @@ class Host(Problem_Mixin):
"%s:%s" % (self.timestamp, ":".join(str(v) for v in self.field_values))])
def rrd_graph(self, html):
- filebase = os.path.join(opt["output_directory"], self.hostname)
+ filebase = os.path.join(args.output_directory, self.hostname)
formats = [format for format in ("png", "svg", "eps")
- if opt[format + "-width"] and opt[format + "-height"]]
+ if getattr(args, format + "_width") and getattr(args, format + "_height")]
for period, start in self.graph_periods:
for format in formats:
cmds = [ "graph", "%s_%s.%s" % (filebase, period, format),
"--title", "%s last %s" % (self.hostname, period),
"--start", start,
- "--width", opt[format + "-width"],
- "--height", opt[format + "-height"],
+ "--width", getattr(args, format + "_width"),
+ "--height", getattr(args, format + "_height"),
"--imgformat", format.upper() ]
cmds.extend(self.graph_opts)
cmds.extend(self.field_defs(filebase))
cmds.extend(self.graph_cmds)
self.rrd_run(cmds)
img = Element("img", src = "%s_%s.png" % (self.hostname, period),
- width = str(opt["png-width"]),
- height = str(opt["png-height"]))
+ width = str(args.png_width),
+ height = str(args.png_height))
if self.graph is None:
self.graph = copy.copy(img)
html.BodyElement("h2").text = "%s over last %s" % (self.hostname, period)
@@ -375,10 +339,7 @@ class Session(Problem_Mixin):
def __init__(self):
self.hosts = {}
- if opt["input_file"] == "-":
- self.root = ElementTree(file = sys.stdin).getroot()
- else:
- self.root = ElementTree(file = opt["input_file"]).getroot()
+ self.root = ElementTree(file = args.input_file).getroot()
self.rcynic_version = self.root.get("rcynic-version")
self.rcynic_date = self.root.get("date")
@@ -424,7 +385,7 @@ class Session(Problem_Mixin):
for h in self.hosts.itervalues())
def rrd_update(self):
- if opt["update-rrds"]:
+ if not args.dont_update_rrds:
for h in self.hosts.itervalues():
h.rrd_update()
@@ -517,7 +478,7 @@ class HTML(object):
def __init__(self, title, filebase):
- self.filename = os.path.join(opt["output_directory"], filebase + ".html")
+ self.filename = os.path.join(args.output_directory, filebase + ".html")
self.html = Element("html")
self.html.append(Comment(" Generators:\n" +
@@ -531,8 +492,8 @@ class HTML(object):
SubElement(self.body, "h1").text = title
SubElement(self.head, "style", type = "text/css").text = css
- if opt["refresh"]:
- SubElement(self.head, "meta", { "http-equiv" : "Refresh", "content" : str(opt["refresh"]) })
+ if args.refresh:
+ SubElement(self.head, "meta", { "http-equiv" : "Refresh", "content" : str(args.refresh) })
hostwidth = max(len(hostname) for hostname in session.hostnames)
@@ -648,9 +609,9 @@ def main():
for hostname in session.hostnames:
html = HTML("Repository details for %s" % hostname, hostname)
html.counter_table(session.hosts[hostname].get_counter, session.hosts[hostname].get_total)
- if opt["show-graphs"]:
+ if not args.hide_graphs:
session.hosts[hostname].rrd_graph(html)
- if opt["show-problems"]:
+ if not args.hide_problems:
html.BodyElement("h2").text = "Connection Problems"
html.detail_table(session.hosts[hostname].connection_problems)
html.BodyElement("h2").text = "Object Problems"
@@ -660,7 +621,7 @@ def main():
html = HTML("rcynic summary", "index")
html.BodyElement("h2").text = "Grand totals for all repositories"
html.counter_table(session.get_sum, Label.get_count)
- if opt["show-object-counts"]:
+ if not args.hide_object_counts:
html.BodyElement("br")
html.BodyElement("hr")
html.BodyElement("br")
@@ -672,7 +633,7 @@ def main():
html.BodyElement("br")
html.BodyElement("h2").text = "Overview for repository %s" % hostname
html.counter_table(session.hosts[hostname].get_counter, session.hosts[hostname].get_total)
- if opt["show-graphs"]:
+ if not args.hide_graphs:
html.BodyElement("br")
html.BodyElement("a", href = "%s.html" % hostname).append(session.hosts[hostname].graph)
html.close()
diff --git a/rcynic/rpki-torrent.py b/rcynic/rpki-torrent.py
index 6068d642..9b97f298 100644
--- a/rcynic/rpki-torrent.py
+++ b/rcynic/rpki-torrent.py
@@ -1,22 +1,22 @@
#!/usr/local/bin/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,
-INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-"""
+# $Id$
+#
+# Copyright (C) 2013--2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 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
+# ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
import urllib2
import httplib
@@ -37,7 +37,7 @@ import stat
import time
import errno
import fcntl
-import getopt
+import argparse
import smtplib
import email.mime.text
@@ -82,20 +82,17 @@ def main():
syslog_flags |= syslog.LOG_PERROR
syslog.openlog("rpki-torrent", syslog_flags)
- cfg_file = [os.path.join(dn, fn)
- for fn in ("rcynic.conf", "rpki.conf")
- for dn in ("/var/rcynic/etc", "/usr/local/etc", "/etc")]
-
- opts, argv = getopt.getopt(sys.argv[1:], "c:h?", ["config=", "help"])
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- raise UseTheSourceLuke
- elif o in ("-c", "--config"):
- cfg_file = a
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-c", "--config",
+ help = "configuration file")
+ args = parser.parse_args()
global cfg
cfg = MyConfigParser()
- cfg.read(cfg_file)
+ cfg.read(args.config or
+ [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:
if len(argv) == 1 and argv[0] == "generate":