3 from cStringIO import StringIO
5 from twisted.python import usage
8 from allmydata.scripts.common import BaseOptions
9 from allmydata.scripts import debug, create_node, startstop_node, cli, keygen, stats_gatherer
10 from allmydata.util.encodingutil import quote_output, get_argv_encoding
13 # Usage.parseOptions compares argv[1] against command[0], so it will
14 # effectively ignore any "subcommand" that starts with a newline. We use
15 # these to insert section headers into the --help output.
16 return [("\n" + s, None, None, None)]
19 class Options(BaseOptions, usage.Options):
20 synopsis = "\nUsage: tahoe <command> [command options]"
21 subCommands = ( GROUP("Administration")
22 + create_node.subCommands
24 + stats_gatherer.subCommands
25 + GROUP("Controlling a node")
26 + startstop_node.subCommands
29 + GROUP("Using the filesystem")
33 def getUsage(self, **kwargs):
34 t = usage.Options.getUsage(self, **kwargs)
35 return t + "\nPlease run 'tahoe <command> --help' for more details on each command.\n"
37 def postOptions(self):
38 if not hasattr(self, 'subOptions'):
39 raise usage.UsageError("must specify a command")
43 for module in (create_node, keygen, stats_gatherer):
44 create_dispatch.update(module.dispatch)
48 stdin=None, stdout=None, stderr=None,
49 install_node_control=True, additional_commands=None):
51 stdin = stdin or sys.stdin
52 stdout = stdout or sys.stdout
53 stderr = stderr or sys.stderr
56 if install_node_control:
57 config.subCommands.extend(startstop_node.subCommands)
60 if additional_commands:
61 for ac in additional_commands:
62 config.subCommands.extend(ac.subCommands)
63 ac_dispatch.update(ac.dispatch)
66 config.parseOptions(argv)
67 except usage.error, e:
71 while hasattr(c, 'subOptions'):
73 print >>stdout, str(c)
75 msg = e.args[0].decode(get_argv_encoding())
78 print >>stdout, "%s: %s\n" % (sys.argv[0], quote_output(msg, quotemarks=False))
81 command = config.subCommand
82 so = config.subOptions
92 if command in create_dispatch:
93 f = create_dispatch[command]
94 for basedir in so.basedirs:
95 rc = f(basedir, so, stdout, stderr) or rc
96 elif command in startstop_node.dispatch:
97 rc = startstop_node.dispatch[command](so, stdout, stderr)
98 elif command in debug.dispatch:
99 rc = debug.dispatch[command](so)
100 elif command in cli.dispatch:
101 rc = cli.dispatch[command](so)
102 elif command in ac_dispatch:
103 rc = ac_dispatch[command](so, stdout, stderr)
105 raise usage.UsageError()
110 def run(install_node_control=True):
111 if sys.platform == "win32":
112 from allmydata.windows.fixups import initialize
115 rc = runner(sys.argv[1:], install_node_control=install_node_control)