3 from cStringIO import StringIO
4 from twisted.python import usage
6 from allmydata.scripts.common import BaseOptions
7 import debug, create_node, startstop_node, cli, keygen
9 _general_commands = ( create_node.subCommands
15 class Options(BaseOptions, usage.Options):
16 synopsis = "Usage: tahoe <command> [command options]"
19 subCommands += _general_commands
20 subCommands += startstop_node.subCommands
22 def postOptions(self):
23 if not hasattr(self, 'subOptions'):
24 raise usage.UsageError("must specify a command")
28 stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr,
29 install_node_control=True, additional_commands=None):
32 if install_node_control:
33 config.subCommands.extend(startstop_node.subCommands)
36 if additional_commands:
37 for ac in additional_commands:
38 config.subCommands.extend(ac.subCommands)
39 ac_dispatch.update(ac.dispatch)
42 config.parseOptions(argv)
43 except usage.error, e:
46 print "%s: %s" % (sys.argv[0], e)
48 c = getattr(config, 'subOptions', config)
52 command = config.subCommand
53 so = config.subOptions
63 if command in create_node.dispatch:
64 for basedir in so.basedirs:
65 f = create_node.dispatch[command]
66 rc = f(basedir, so, stdout, stderr) or rc
67 elif command in startstop_node.dispatch:
68 rc = startstop_node.dispatch[command](so, stdout, stderr)
69 elif command in debug.dispatch:
70 rc = debug.dispatch[command](so, stdout, stderr)
71 elif command in cli.dispatch:
72 rc = cli.dispatch[command](so)
73 elif command in keygen.dispatch:
74 rc = keygen.dispatch[command](so, stdout, stderr)
75 elif command in ac_dispatch:
76 rc = ac_dispatch[command](so, stdout, stderr)
78 raise usage.UsageError()
82 def run(install_node_control=True):
83 rc = runner(sys.argv[1:])