3 from cStringIO import StringIO
6 pkg_resources.require('twisted')
7 from twisted.python import usage
9 pkg_resources.require('allmydata-tahoe')
10 from allmydata.scripts.common import BaseOptions
11 import debug, create_node, startstop_node, cli, keygen, stats_gatherer
14 # Usage.parseOptions compares argv[1] against command[0], so it will
15 # effectively ignore any "subcommand" that starts with a newline. We use
16 # these to insert section headers into the --help output.
17 return [("\n" + s, None, None, None)]
20 class Options(BaseOptions, usage.Options):
21 synopsis = "Usage: tahoe <command> [command options]"
22 subCommands = ( GROUP("Administration")
23 + create_node.subCommands
25 + stats_gatherer.subCommands
26 + GROUP("Controlling a node")
27 + startstop_node.subCommands
30 + GROUP("Using the filesystem")
34 def getUsage(self, **kwargs):
35 t = usage.Options.getUsage(self, **kwargs)
36 return t + "\nPlease run 'tahoe <command> --help' for more details on each command.\n"
38 def postOptions(self):
39 if not hasattr(self, 'subOptions'):
40 raise usage.UsageError("must specify a command")
44 stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr,
45 install_node_control=True, additional_commands=None):
48 if install_node_control:
49 config.subCommands.extend(startstop_node.subCommands)
52 if additional_commands:
53 for ac in additional_commands:
54 config.subCommands.extend(ac.subCommands)
55 ac_dispatch.update(ac.dispatch)
58 config.parseOptions(argv)
59 except usage.error, e:
63 while hasattr(c, 'subOptions'):
66 print "%s: %s" % (sys.argv[0], e)
69 command = config.subCommand
70 so = config.subOptions
80 if command in create_node.dispatch:
81 for basedir in so.basedirs:
82 f = create_node.dispatch[command]
83 rc = f(basedir, so, stdout, stderr) or rc
84 elif command in startstop_node.dispatch:
85 rc = startstop_node.dispatch[command](so, stdout, stderr)
86 elif command in debug.dispatch:
87 rc = debug.dispatch[command](so)
88 elif command in cli.dispatch:
89 rc = cli.dispatch[command](so)
90 elif command in keygen.dispatch:
91 rc = keygen.dispatch[command](so, stdout, stderr)
92 elif command in stats_gatherer.dispatch:
93 rc = stats_gatherer.dispatch[command](so)
94 elif command in ac_dispatch:
95 rc = ac_dispatch[command](so, stdout, stderr)
97 raise usage.UsageError()
101 def run(install_node_control=True):
102 rc = runner(sys.argv[1:])