diff options
author | Rob Austein <sra@hactrn.net> | 2007-08-03 18:22:43 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-08-03 18:22:43 +0000 |
commit | 0cdbc4a3263eaa1c83fd500bad4618e3fd9790ed (patch) | |
tree | 366d07b816f82ca027d289f024a39418dfbca7bd /scripts | |
parent | 7ed3ca7909edc5bc5f755770c860babf3ab36d52 (diff) |
Checkpoint
svn path=/scripts/irbe-cli.py; revision=824
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/irbe-cli.py | 50 |
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]() |