aboutsummaryrefslogtreecommitdiff
path: root/scripts/irbe-cli.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-08-06 15:22:28 +0000
committerRob Austein <sra@hactrn.net>2007-08-06 15:22:28 +0000
commit8becf9cf697252d70b65550ec45f9cc347c80c3d (patch)
treedd674ca0a06f0dbc0bd0060415bfe2f17df0462f /scripts/irbe-cli.py
parent0cdbc4a3263eaa1c83fd500bad4618e3fd9790ed (diff)
Checkpoint
svn path=/scripts/irbe-cli.py; revision=825
Diffstat (limited to 'scripts/irbe-cli.py')
-rwxr-xr-xscripts/irbe-cli.py59
1 files changed, 35 insertions, 24 deletions
diff --git a/scripts/irbe-cli.py b/scripts/irbe-cli.py
index 5a29774a..b2be9e16 100755
--- a/scripts/irbe-cli.py
+++ b/scripts/irbe-cli.py
@@ -11,37 +11,48 @@ rng = lxml.etree.RelaxNG(lxml.etree.parse("left-right-schema.rng"))
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)
+ def getopt(self, argv):
+ if options:
+ opts, args = getopt.getopt(argv, "", [x[2:] for x in self.options])
+ for o, a in opts:
+ getattr(self, o[2:])(a)
+ return args
+ else:
+ return argv
+
+ def self_id(self, arg):
+ self.self_id = arg
+
+
class help(command):
- options = ('--tweedledee', '--tweedledum')
+ def run(self, msg):
+ print "Usage:", sys.argv[0]
+ for k,v in dispatch.iteritems():
+ print " ".join((k,) + v.options)
+
+class self(command):
+ options = ("--action", "--self_id", "--extension")
- def tweedledee(self, arg): print "tweedledee"
+ def __init__(self):
+ self.extensions = {}
- def tweedledum(self, arg): print "tweedledum"
+ def extension(self, arg):
+ kv = arg.split(":", 1)
+ self.extensions[k] = v
- def __call__(self):
- print "Boy this sure is an interesting help command, huh?"
+ def run(self, msg):
+ pdu = rpki.left_right.self_elt()
+
-class wombat(command):
- def __call__(self):
- print "I am the wombat!"
-top_dispatch = dict((x.__name__, x) for x in (help, wombat))
+dispatch = dict((x.__name__, x) for x in (help, self))
-cmd = top_dispatch[sys.argv[1]](sys.argv)
-cmd()
+msg = rpki.left_right.msg()
-if False:
+argv = sys.argv[1:]
+while argv:
+ cmd = dispatch[argv[0]]
+ argv = getopt(argv[1:])
+ cmd.run(msg)
- 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]()