aboutsummaryrefslogtreecommitdiff
path: root/scripts/irbe-cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/irbe-cli.py')
-rwxr-xr-xscripts/irbe-cli.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/scripts/irbe-cli.py b/scripts/irbe-cli.py
index c9df0d9a..5a29774a 100755
--- a/scripts/irbe-cli.py
+++ b/scripts/irbe-cli.py
@@ -4,18 +4,44 @@
Command line program to simulate behavior of the IR back-end.
"""
-import glob, rpki.left_right, xml.sax, lxml.etree, lxml.sax, POW, POW.pkix, getopt
+import glob, rpki.left_right, xml.sax, lxml.etree, lxml.sax, POW, POW.pkix, getopt, sys
rng = lxml.etree.RelaxNG(lxml.etree.parse("left-right-schema.rng"))
-files = glob.glob("left-right-protocol-samples/*.xml")
-files.sort()
-for f in files:
- print "\n<!--", f, "-->"
- handler = rpki.left_right.sax_handler()
- elt_in = lxml.etree.parse(f).getroot()
- rng.assertValid(elt_in)
- lxml.sax.saxify(elt_in, handler)
- elt_out = handler.result.toXML()
- rng.assertValid(elt_out)
- print lxml.etree.tostring(elt_out, pretty_print=True, encoding="us-ascii", xml_declaration=True)
+class command(object):
+ options = ()
+
+ def __init__(self, argv):
+ opts, args = getopt.getopt(argv[2:], "", [x[2:] for x in self.options])
+ for o, a in opts:
+ getattr(self, o[2:])(a)
+
+class help(command):
+ options = ('--tweedledee', '--tweedledum')
+
+ def tweedledee(self, arg): print "tweedledee"
+
+ def tweedledum(self, arg): print "tweedledum"
+
+ def __call__(self):
+ print "Boy this sure is an interesting help command, huh?"
+
+class wombat(command):
+ def __call__(self):
+ print "I am the wombat!"
+
+top_dispatch = dict((x.__name__, x) for x in (help, wombat))
+
+cmd = top_dispatch[sys.argv[1]](sys.argv)
+cmd()
+
+if False:
+
+ dispatch = { "--help" : help, "--usage" : usage, "--wombat" : wombat }
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "", [x[2:] for x in dispatch.keys()])
+ except getopt.GetoptError:
+ print "You're confused, aren't you?"
+ sys.exit(1)
+ for o, a in opts:
+ dispatch[o]()