aboutsummaryrefslogtreecommitdiff
path: root/scripts/irbe-cli.py
blob: 5a29774a3ea00f3eb62b5644a429bf9f56f051f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# $Id$

"""
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, sys

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)

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]()