From 770fd45ccc3baa44886c420858bc3899b2741d7b Mon Sep 17 00:00:00 2001 From: David-Sarah Hopwood Date: Thu, 3 Jan 2013 18:53:39 +0000 Subject: [PATCH] startstop_node.py: improve error reporting and help. --- src/allmydata/scripts/startstop_node.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py index 90ec1046..a0c69bb6 100644 --- a/src/allmydata/scripts/startstop_node.py +++ b/src/allmydata/scripts/startstop_node.py @@ -7,7 +7,12 @@ from allmydata.util import fileutil from allmydata.util.encodingutil import listdir_unicode, quote_output +def format_twisted_options(config): + return "twistd %s\n" % (str(config).partition("\n")[2].partition("\n\n")[0],) + class StartOptions(BasedirOptions): + subcommand_name = "start" + def parseArgs(self, basedir=None, *twistd_args): # this can't handle e.g. 'tahoe start --nodaemon', since then # --nodaemon looks like a basedir. So you can either use 'tahoe @@ -19,22 +24,22 @@ class StartOptions(BasedirOptions): self.twistd_args = twistd_args def getSynopsis(self): - return "Usage: %s [global-opts] start [options] [NODEDIR]" % (self.command_name,) + return "Usage: %s [global-opts] %s [options] [NODEDIR] [twistd_options]" % (self.command_name, self.subcommand_name) + def getUsage(self, width=None): + t = BaseOptions.getUsage(self, width) + "\n" + t += format_twisted_options(MyTwistdConfig()) + return t class StopOptions(BasedirOptions): def getSynopsis(self): return "Usage: %s [global-opts] stop [options] [NODEDIR]" % (self.command_name,) - class RestartOptions(StartOptions): - def getSynopsis(self): - return "Usage: %s [global-opts] restart [options] [NODEDIR]" % (self.command_name,) - + subcommand_name = "restart" class RunOptions(StartOptions): - def getSynopsis(self): - return "Usage: %s [global-opts] run [options] [NODEDIR]" % (self.command_name,) + subcommand_name = "run" class MyTwistdConfig(twistd.ServerOptions): @@ -111,8 +116,9 @@ def start(config, out=sys.stdout, err=sys.stderr): twistd_config.parseOptions(twistd_args) except usage.error, ue: # these arguments were unsuitable for 'twistd' - print >>err, twistd_config - print >>err, "tahoe start: %s" % (config.subCommand, ue) + print >>err, config + print >>err, format_twisted_options(twistd_config) + print >>err, "tahoe %s: %s\n" % (config.subcommand_name, ue) return 1 twistd_config.loadedPlugins = {"StartTahoeNode": StartTahoeNodePlugin(nodetype, basedir)} -- 2.45.2