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