aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2010-03-03 17:40:31 +0000
committerRob Austein <sra@hactrn.net>2010-03-03 17:40:31 +0000
commit127c56f70eb5eab97d2f051a822081b515d5d0e2 (patch)
treefa708c998f46c736c709cf113ce88bf8858a4111
parent1c03ac46cd227a1c80a64e5c277d9ed4b0ad2878 (diff)
Refactor
svn path=/myrpki.rototill/setup.py; revision=3015
-rw-r--r--myrpki.rototill/setup.py51
-rw-r--r--rpkid/rpki/cli.py76
2 files changed, 83 insertions, 44 deletions
diff --git a/myrpki.rototill/setup.py b/myrpki.rototill/setup.py
index 964c8964..fb4760bb 100644
--- a/myrpki.rototill/setup.py
+++ b/myrpki.rototill/setup.py
@@ -16,19 +16,18 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-import subprocess, csv, re, os, getopt, sys, base64, time, cmd, readline, glob
-import myrpki, rpki.config
+import subprocess, csv, re, os, getopt, sys, base64, time, glob
+import myrpki, rpki.config, rpki.cli
from xml.etree.ElementTree import Element, SubElement, ElementTree
-class main(cmd.Cmd):
+class main(rpki.cli.Cmd):
prompt = "setup> "
- identchars = cmd.IDENTCHARS + "/-."
+ completedefault = rpki.cli.Cmd.filename_complete
def __init__(self):
- cmd.Cmd.__init__(self)
os.environ["TZ"] = "UTC"
time.tzset()
@@ -39,11 +38,11 @@ class main(cmd.Cmd):
if o in ("-c", "--config"):
self.cfg_file = a
elif o in ("-h", "--help", "-?"):
- print __doc__
- sys.exit(0)
+ argv = ["help"]
self.cfg = rpki.config.parser(self.cfg_file, "myrpki")
myrpki.openssl = self.cfg.get("openssl", "openssl")
+ self.histfile = self.cfg.get("history_file", ".setup_history")
self.handle = self.cfg.get("handle")
self.run_rpkid = self.cfg.getboolean("run_rpkid")
@@ -57,43 +56,7 @@ class main(cmd.Cmd):
if self.run_rpkid or self.run_pubd or self.run_rootd:
self.bpki_myirbe = myrpki.CA(self.cfg_file, self.cfg.get("myirbe_bpki_directory"))
- if argv:
- self.onecmd(" ".join(argv))
- else:
- self.cmdloop_with_history()
-
- def completedefault(self, text, line, begidx, endidx):
- return glob.glob(text + "*")
-
- def cmdloop_with_history(self):
- old_completer_delims = readline.get_completer_delims()
- histfile = self.cfg.get("history_file", ".setup_history")
- try:
- readline.read_history_file(histfile)
- except IOError:
- pass
- try:
- readline.set_completer_delims("".join(set(old_completer_delims) - set(self.identchars)))
- self.cmdloop()
- finally:
- if readline.get_current_history_length():
- readline.write_history_file(histfile)
- readline.set_completer_delims(old_completer_delims)
-
- def do_EOF(self, arg):
- print
- return True
-
- def do_exit(self, arg):
- """
- Exit program
- """
- return True
-
- do_quit = do_exit
-
- def emptyline(self):
- pass
+ rpki.cli.Cmd.__init__(self, argv)
def do_initialize(self, arg):
self.bpki_myrpki.setup(self.cfg.get("bpki_myrpki_ta_dn",
diff --git a/rpkid/rpki/cli.py b/rpkid/rpki/cli.py
new file mode 100644
index 00000000..4960c387
--- /dev/null
+++ b/rpkid/rpki/cli.py
@@ -0,0 +1,76 @@
+"""
+Customizations of Python cmd module.
+
+$Id$
+
+Copyright (C) 2010 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.
+"""
+
+import cmd, glob
+
+try:
+ import readline
+ have_readline = True
+except ImportError:
+ have_readline = False
+
+class Cmd(cmd.Cmd):
+
+ identchars = cmd.IDENTCHARS + "/-."
+
+ histfile = None
+
+ def __init__(self, argv = None):
+ cmd.Cmd.__init__(self)
+ if argv:
+ self.onecmd(" ".join(argv))
+ else:
+ self.cmdloop_with_history()
+
+ def do_EOF(self, arg):
+ print
+ return True
+
+ def do_exit(self, arg):
+ return True
+
+ do_quit = do_exit
+
+ def emptyline(self):
+ pass
+
+ def filename_complete(self, text, line, begidx, endidx):
+ return glob.glob(text + "*")
+
+ if have_readline:
+
+ def cmdloop_with_history(self):
+ old_completer_delims = readline.get_completer_delims()
+ if self.histfile is not None:
+ try:
+ readline.read_history_file(self.histfile)
+ except IOError:
+ pass
+ try:
+ readline.set_completer_delims("".join(set(old_completer_delims) - set(self.identchars)))
+ self.cmdloop()
+ finally:
+ if self.histfile is not None and readline.get_current_history_length():
+ readline.write_history_file(self.histfile)
+ readline.set_completer_delims(old_completer_delims)
+
+ else:
+
+ cmdloop_with_history = cmd.Cmd.cmdloop