2006-12-05 19:25:23 +00:00
|
|
|
|
2007-07-11 02:05:18 +00:00
|
|
|
import sys
|
2007-06-26 23:19:18 +00:00
|
|
|
from cStringIO import StringIO
|
2006-12-05 19:25:23 +00:00
|
|
|
from twisted.python import usage
|
|
|
|
|
2007-07-11 02:05:18 +00:00
|
|
|
from allmydata.scripts import debug, create_node, startstop_node
|
2006-12-05 19:25:23 +00:00
|
|
|
|
|
|
|
class Options(usage.Options):
|
|
|
|
synopsis = "Usage: allmydata <command> [command options]"
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
optFlags = [
|
|
|
|
["quiet", "q", "operate silently"],
|
|
|
|
]
|
|
|
|
|
2007-07-11 02:05:18 +00:00
|
|
|
subCommands = []
|
|
|
|
subCommands += create_node.subCommands
|
|
|
|
subCommands += startstop_node.subCommands
|
|
|
|
subCommands += debug.subCommands
|
2006-12-05 19:25:23 +00:00
|
|
|
|
|
|
|
def postOptions(self):
|
|
|
|
if not hasattr(self, 'subOptions'):
|
|
|
|
raise usage.UsageError("must specify a command")
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr):
|
2006-12-05 19:25:23 +00:00
|
|
|
config = Options()
|
|
|
|
try:
|
2007-04-20 01:56:45 +00:00
|
|
|
config.parseOptions(argv)
|
2006-12-05 19:25:23 +00:00
|
|
|
except usage.error, e:
|
2007-04-24 04:28:19 +00:00
|
|
|
if not run_by_human:
|
|
|
|
raise
|
2006-12-05 19:25:23 +00:00
|
|
|
print "%s: %s" % (sys.argv[0], e)
|
|
|
|
print
|
|
|
|
c = getattr(config, 'subOptions', config)
|
|
|
|
print str(c)
|
2007-04-20 01:56:45 +00:00
|
|
|
return 1
|
2006-12-05 19:25:23 +00:00
|
|
|
|
|
|
|
command = config.subCommand
|
|
|
|
so = config.subOptions
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
if config['quiet']:
|
|
|
|
stdout = StringIO()
|
|
|
|
|
2007-06-06 21:06:57 +00:00
|
|
|
rc = 0
|
2007-07-11 02:05:18 +00:00
|
|
|
if command in create_node.dispatch:
|
2007-06-06 21:06:57 +00:00
|
|
|
for basedir in so.basedirs:
|
2007-07-11 02:05:18 +00:00
|
|
|
f = create_node.dispatch[command]
|
|
|
|
rc = f(basedir, so, stdout, stderr) or rc
|
|
|
|
elif command in startstop_node.dispatch:
|
|
|
|
rc = startstop_node.dispatch[command](so, stdout, stderr)
|
2007-07-11 01:41:52 +00:00
|
|
|
elif command in debug.dispatch:
|
|
|
|
rc = debug.dispatch[command](so, stdout, stderr)
|
|
|
|
|
2007-04-20 01:56:45 +00:00
|
|
|
return rc
|
|
|
|
|
|
|
|
def run():
|
|
|
|
rc = runner(sys.argv[1:])
|
2006-12-05 19:25:23 +00:00
|
|
|
sys.exit(rc)
|