aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2014-01-09 01:51:08 +0000
committerRob Austein <sra@hactrn.net>2014-01-09 01:51:08 +0000
commit06023dcd60af34a84c3a71f1a597e477cfa8f408 (patch)
tree1775f6ef71d3114e890d5e1c0828f36e461b632a
parent98ecedb99f88cf0a8e3a290b103322b156b88716 (diff)
getopt -> argparse, update copyright.
svn path=/trunk/; revision=5623
-rw-r--r--rpkid/rpki/irdbd.py108
-rw-r--r--rpkid/rpki/pubd.py105
-rw-r--r--rpkid/rpki/rootd.py100
-rw-r--r--rpkid/rpki/rpkic.py91
-rw-r--r--rpkid/rpki/rpkid.py108
5 files changed, 206 insertions, 306 deletions
diff --git a/rpkid/rpki/irdbd.py b/rpkid/rpki/irdbd.py
index 4da6f5e1..b4799f09 100644
--- a/rpkid/rpki/irdbd.py
+++ b/rpkid/rpki/irdbd.py
@@ -1,46 +1,30 @@
"""
IR database daemon.
-
-Usage: python irdbd.py [ { -c | --config } configfile ]
- [ { -d | --debug } ]
- [ { -f | --foreground } ]
- [ { -h | --help } ]
-
-$Id$
-
-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 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.
-
-Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
-
-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 ARIN DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS. IN NO EVENT SHALL ARIN 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) 2009--2012 Internet Systems Consortium ("ISC")
+# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+#
+# 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, ISC, AND ARIN DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
+# ISC, OR ARIN 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 sys
import os
import time
-import getopt
+import argparse
import urlparse
import rpki.http
import rpki.config
@@ -148,45 +132,35 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- cfg_file = None
- foreground = False
- profile = None
- use_syslog = True
-
- opts, argv = getopt.getopt(sys.argv[1:], "c:dfhp:?",
- ["config=", "debug", "foreground", "help", "profile="])
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- print __doc__
- sys.exit(0)
- if o in ("-c", "--config"):
- cfg_file = a
- elif o in ("-d", "--debug"):
- use_syslog = False
- foreground = True
- elif o in ("-f", "--foreground"):
- foreground = True
- elif o in ("-p", "--profile"):
- profile = a
- if argv:
- raise rpki.exceptions.CommandParseFailure("Unexpected arguments %s" % argv)
-
- rpki.log.init("irdbd", use_syslog = use_syslog)
-
- self.cfg = rpki.config.parser(cfg_file, "irdbd")
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-c", "--config",
+ help = "override default location of configuration file")
+ parser.add_argument("-d", "--debug", action = "store_true",
+ help = "enable debugging mode")
+ parser.add_argument("-f", "--foreground", action = "store_true",
+ help = "do not daemonize")
+ parser.add_argument("--pidfile",
+ help = "override default location of pid file")
+ parser.add_argument("--profile",
+ help = "enable profiling, saving data to PROFILE")
+ args = parser.parse_args()
+
+ rpki.log.init("irdbd", use_syslog = not args.debug)
+
+ self.cfg = rpki.config.parser(args.config, "irdbd")
self.cfg.set_global_flags()
- if not foreground:
- rpki.daemonize.daemon()
+ if not args.foreground and not args.debug:
+ rpki.daemonize.daemon(pidfile = args.pidfile)
- if profile:
+ if args.profile:
import cProfile
prof = cProfile.Profile()
try:
prof.runcall(self.main)
finally:
- prof.dump_stats(profile)
- rpki.log.info("Dumped profile data to %s" % profile)
+ prof.dump_stats(args.profile)
+ rpki.log.info("Dumped profile data to %s" % args.profile)
else:
self.main()
diff --git a/rpkid/rpki/pubd.py b/rpkid/rpki/pubd.py
index 7c5426bd..17a79ebf 100644
--- a/rpkid/rpki/pubd.py
+++ b/rpkid/rpki/pubd.py
@@ -1,46 +1,29 @@
"""
RPKI publication engine.
-
-Usage: python pubd.py [ { -c | --config } configfile ]
- [ { -d | --debug } ]
- [ { -f | --foreground } ]
- [ { -h | --help } ]
- [ { -p | --profile } outputfile ]
-
-$Id$
-
-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 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.
-
-Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
-
-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 ARIN DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS. IN NO EVENT SHALL ARIN 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) 2009--2012 Internet Systems Consortium ("ISC")
+# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+#
+# 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, ISC, AND ARIN DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
+# ISC, OR ARIN 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 os
import time
-import getopt
+import argparse
import sys
import re
import rpki.resource_set
@@ -65,38 +48,30 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = None
- self.profile = False
- self.foreground = False
self.irbe_cms_timestamp = None
- use_syslog = True
-
- opts, argv = getopt.getopt(sys.argv[1:], "c:dfhp:?",
- ["config=", "debug", "foreground", "help", "profile="])
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- print __doc__
- sys.exit(0)
- elif o in ("-c", "--config"):
- self.cfg_file = a
- elif o in ("-d", "--debug"):
- use_syslog = False
- self.foreground = True
- elif o in ("-f", "--foreground"):
- self.foreground = True
- elif o in ("-p", "--profile"):
- self.profile = a
- if argv:
- raise rpki.exceptions.CommandParseFailure, "Unexpected arguments %s" % argv
-
- rpki.log.init("pubd", use_syslog = use_syslog)
-
- self.cfg = rpki.config.parser(self.cfg_file, "pubd")
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-c", "--config",
+ help = "override default location of configuration file")
+ parser.add_argument("-d", "--debug", action = "store_true",
+ help = "enable debugging mode")
+ parser.add_argument("-f", "--foreground", action = "store_true",
+ help = "do not daemonize")
+ parser.add_argument("--pidfile",
+ help = "override default location of pid file")
+ parser.add_argument("--profile",
+ help = "enable profiling, saving data to PROFILE")
+ args = parser.parse_args()
+
+ self.profile = args.profile
+
+ rpki.log.init("pubd", use_syslog = not args.debug)
+
+ self.cfg = rpki.config.parser(args.config, "pubd")
self.cfg.set_global_flags()
- if not self.foreground:
- rpki.daemonize.daemon()
+ if not args.foreground and not args.debug:
+ rpki.daemonize.daemon(pidfile = args.pidfile)
if self.profile:
import cProfile
diff --git a/rpkid/rpki/rootd.py b/rpkid/rpki/rootd.py
index f9f2d254..c56cf684 100644
--- a/rpkid/rpki/rootd.py
+++ b/rpkid/rpki/rootd.py
@@ -1,47 +1,31 @@
"""
-Trivial RPKI up-down protocol root server, for testing. Not suitable
-for production use. Overrides a bunch of method definitions from the
+Trivial RPKI up-down protocol root server. Not recommended for
+production use. Overrides a bunch of method definitions from the
rpki.* classes in order to reuse as much code as possible.
-
-Usage: python rootd.py [ { -c | --config } configfile ]
- [ { -d | --debug } ]
- [ { -f | --foreground } ]
- [ { -h | --help } ]
-
-$Id$
-
-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 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.
-
-Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
-
-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 ARIN DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS. IN NO EVENT SHALL ARIN 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) 2009--2012 Internet Systems Consortium ("ISC")
+# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+#
+# 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, ISC, AND ARIN DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
+# ISC, OR ARIN 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 os
import time
-import getopt
+import argparse
import sys
import rpki.resource_set
import rpki.up_down
@@ -131,7 +115,8 @@ class main(object):
self.rpki_root_cert = rpki.x509.X509(Auto_file = self.rpki_root_cert_file)
def root_newer_than_subject(self):
- return os.stat(self.rpki_root_cert_file).st_mtime > os.stat(os.path.join(self.rpki_root_dir, self.rpki_subject_cert)).st_mtime
+ return os.stat(self.rpki_root_cert_file).st_mtime > \
+ os.stat(os.path.join(self.rpki_root_dir, self.rpki_subject_cert)).st_mtime
def get_subject_cert(self):
filename = os.path.join(self.rpki_root_dir, self.rpki_subject_cert)
@@ -344,38 +329,29 @@ class main(object):
self.serial_number = None
self.crl_number = None
self.revoked = []
- self.foreground = False
self.cms_timestamp = None
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = None
- use_syslog = True
-
- opts, argv = getopt.getopt(sys.argv[1:], "c:dfh?", ["config=", "debug", "foreground", "help"])
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- print __doc__
- sys.exit(0)
- elif o in ("-c", "--config"):
- self.cfg_file = a
- elif o in ("-d", "--debug"):
- use_syslog = False
- self.foreground = True
- elif o in ("-f", "--foreground"):
- self.foreground = True
-
- if argv:
- raise rpki.exceptions.CommandParseFailure, "Unexpected arguments %s" % argv
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-c", "--config",
+ help = "override default location of configuration file")
+ parser.add_argument("-d", "--debug", action = "store_true",
+ help = "enable debugging mode")
+ parser.add_argument("-f", "--foreground", action = "store_true",
+ help = "do not daemonize")
+ parser.add_argument("--pidfile",
+ help = "override default location of pid file")
+ args = parser.parse_args()
- rpki.log.init("rootd", use_syslog = use_syslog)
+ rpki.log.init("rootd", use_syslog = not args.debug)
- self.cfg = rpki.config.parser(self.cfg_file, "rootd")
+ self.cfg = rpki.config.parser(args.config, "rootd")
self.cfg.set_global_flags()
- if not self.foreground:
- rpki.daemonize.daemon()
+ if not args.foreground and not args.debug:
+ rpki.daemonize.daemon(pidfile = args.pidfile)
self.bpki_ta = rpki.x509.X509(Auto_update = self.cfg.get("bpki-ta"))
self.rootd_bpki_key = rpki.x509.RSA( Auto_update = self.cfg.get("rootd-bpki-key"))
diff --git a/rpkid/rpki/rpkic.py b/rpkid/rpki/rpkic.py
index 64f9e69f..8d9d77d5 100644
--- a/rpkid/rpki/rpkic.py
+++ b/rpkid/rpki/rpkic.py
@@ -1,37 +1,29 @@
"""
-This is a command line configuration and control tool for rpkid et al.
+Command line configuration and control tool for rpkid et al.
-Type "help" on the prompt, or run the program with the --help option for an
-overview of the available commands; type "help foo" for (more) detailed help
+Type "help" at the inernal prompt, or run the program with the --help option for
+an overview of the available commands; type "help foo" for (more) detailed help
on the "foo" command.
-
-
-This program is a rewrite of the old myrpki program, replacing ten
-zillion XML and X.509 disk files and subprocess calls to the OpenSSL
-command line tool with SQL data and direct calls to the rpki.POW
-library. This version abandons all pretense that this program might
-somehow work without rpki.POW, lxml, and Django installed, but since
-those packages are required for rpkid anyway, this seems like a small
-price to pay for major simplification of the code and better
-integration with the Django-based GUI interface.
-
-$Id$
-
-Copyright (C) 2009--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
-PERFORMANCE OF THIS SOFTWARE.
"""
+# $Id$
+#
+# Copyright (C) 2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 2009--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
+# 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.
+
# NB: As of this writing, I'm trying really hard to avoid having this
# program depend on a Django settings.py file. This may prove to be a
# waste of time in the long run, but for for now, this means that one
@@ -41,6 +33,7 @@ PERFORMANCE OF THIS SOFTWARE.
import os
import getopt
+import argparse
import sys
import time
import rpki.config
@@ -74,32 +67,38 @@ class main(Cmd):
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = None
- self.handle = None
- profile = None
+ # We have to override argparse's default "help" mechanism so that
+ # we can add all the help stuff from our internal command
+ # processor.
- opts, self.argv = getopt.getopt(sys.argv[1:], "c:hi:?",
- ["config=", "help", "identity=", "profile="])
- for o, a in opts:
- if o in ("-c", "--config"):
- self.cfg_file = a
- elif o in ("-h", "--help", "-?"):
- self.argv = ["help"]
- elif o in ("-i", "--identity"):
- self.handle = a
- elif o == "--profile":
- profile = a
+ parser = argparse.ArgumentParser(description = __doc__, add_help = False)
+ parser.add_argument("-c", "--config",
+ help = "override default location of configuration file")
+ parser.add_argument("-h", "--help", action = "store_true",
+ help = "show this help message and exit")
+ parser.add_argument("-i", "--identity", "--handle",
+ help = "set initial entity handdle")
+ parser.add_argument("--profile",
+ help = "enable profiling, saving data to PROFILE")
+ args, self.argv = parser.parse_known_args()
+
+ self.cfg_file = args.config
+ self.handle = args.identity
+
+ if args.help:
+ self.argv = ["help"]
+ parser.print_help()
if self.argv and self.argv[0] == "help":
Cmd.__init__(self, self.argv)
- elif profile:
+ elif args.profile:
import cProfile
prof = cProfile.Profile()
try:
prof.runcall(self.main)
finally:
- prof.dump_stats(profile)
- print "Dumped profile data to %s" % profile
+ prof.dump_stats(args.profile)
+ print "Dumped profile data to %s" % args.profile
else:
self.main()
diff --git a/rpkid/rpki/rpkid.py b/rpkid/rpki/rpkid.py
index 88b38cc4..e0e88479 100644
--- a/rpkid/rpki/rpkid.py
+++ b/rpkid/rpki/rpkid.py
@@ -1,46 +1,29 @@
"""
-RPKI engine daemon.
-
-Usage: python rpkid.py [ { -c | --config } configfile ]
- [ { -d | --debug } ]
- [ { -f | --foreground } ]
- [ { -h | --help } ]
- [ { -p | --profile } outputfile ]
-
-$Id$
-
-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 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.
-
-Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
-
-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 ARIN DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS. IN NO EVENT SHALL ARIN 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.
+RPKI CA engine.
"""
+# $Id$
+#
+# Copyright (C) 2013--2014 Dragon Research Labs ("DRL")
+# Portions copyright (C) 2009--2012 Internet Systems Consortium ("ISC")
+# Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+#
+# 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, ISC, AND ARIN DISCLAIM ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL,
+# ISC, OR ARIN 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 os
import time
-import getopt
+import argparse
import sys
import re
import random
@@ -68,40 +51,33 @@ class main(object):
os.environ["TZ"] = "UTC"
time.tzset()
- self.cfg_file = None
- self.profile = None
- self.foreground = False
self.irdbd_cms_timestamp = None
self.irbe_cms_timestamp = None
self.task_current = None
self.task_queue = []
- use_syslog = True
-
- opts, argv = getopt.getopt(sys.argv[1:], "c:dfhp:?",
- ["config=", "debug", "foreground", "help", "profile="])
- for o, a in opts:
- if o in ("-h", "--help", "-?"):
- print __doc__
- sys.exit(0)
- elif o in ("-d", "--debug"):
- use_syslog = False
- self.foreground = True
- elif o in ("-f", "--foreground"):
- self.foreground = True
- elif o in ("-c", "--config"):
- self.cfg_file = a
- elif o in ("-p", "--profile"):
- self.profile = a
- if argv:
- raise rpki.exceptions.CommandParseFailure, "Unexpected arguments %s" % argv
-
- rpki.log.init("rpkid", use_syslog = use_syslog)
-
- self.cfg = rpki.config.parser(self.cfg_file, "rpkid")
+
+ parser = argparse.ArgumentParser(description = __doc__)
+ parser.add_argument("-c", "--config",
+ help = "override default location of configuration file")
+ parser.add_argument("-d", "--debug", action = "store_true",
+ help = "enable debugging mode")
+ parser.add_argument("-f", "--foreground", action = "store_true",
+ help = "do not daemonize")
+ parser.add_argument("--pidfile",
+ help = "override default location of pid file")
+ parser.add_argument("--profile",
+ help = "enable profiling, saving data to PROFILE")
+ args = parser.parse_args()
+
+ self.profile = args.profile
+
+ rpki.log.init("rpkid", use_syslog = not args.debug)
+
+ self.cfg = rpki.config.parser(args.config, "rpkid")
self.cfg.set_global_flags()
- if not self.foreground:
- rpki.daemonize.daemon()
+ if not args.foreground and not args.debug:
+ rpki.daemonize.daemon(pidfile = pidfile)
if self.profile:
import cProfile