class BasedirMixin:
default_nodedir = _default_nodedir
- allow_multiple = True
optParameters = [
["basedir", "C", None, "Same as --node-directory."],
]
- optFlags = [
- ["multiple", "m", "Specify multiple node directories at once."],
- ]
- def parseArgs(self, *args):
+ def parseArgs(self, basedir=None):
if self['node-directory'] and self['basedir']:
raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) "
"options cannot both be used.")
- if self['node-directory'] or self['basedir']:
- self.basedirs = [argv_to_abspath(self['node-directory'] or self['basedir'])]
+ if basedir:
+ b = argv_to_abspath(basedir)
+ elif self['basedir']:
+ b = argv_to_abspath(self['basedir'])
+ elif self['node-directory']:
+ b = argv_to_abspath(self['node-directory'])
else:
- self.basedirs = []
-
- if self.allow_multiple and self['multiple']:
- self.basedirs.extend(map(argv_to_abspath, args))
- else:
- if len(args) > 1:
- raise usage.UsageError("I wasn't expecting so many arguments." +
- (self.allow_multiple and
- " Use the --multiple option to specify more than one node directory." or ""))
-
- if len(args) == 0 and self.default_nodedir and not self.basedirs:
- self.basedirs.append(self.default_nodedir)
- elif len(args) > 0:
- self.basedirs.append(argv_to_abspath(args[0]))
+ b = self.default_nodedir
+ self['basedir'] = b
def postOptions(self):
- if not self.basedirs:
+ if not self['basedir']:
raise usage.UsageError("A base directory for the node must be provided.")
- del self['basedir']
- self['basedirs'] = self.basedirs
DEFAULT_ALIAS = u"tahoe"
c.write("\n")
-def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_node(config, out=sys.stdout, err=sys.stderr):
+ basedir = config['basedir']
# This should always be called with an absolute Unicode basedir.
precondition(isinstance(basedir, unicode), basedir)
print >>out, " The node cannot connect to a grid without it."
if not config.get("nickname", ""):
print >>out, " Please set [node]nickname= in tahoe.cfg"
+ return 0
-
-def create_client(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_client(config, out=sys.stdout, err=sys.stderr):
config['no-storage'] = True
- return create_node(basedir, config, out=out, err=err)
+ return create_node(config, out=out, err=err)
-def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_introducer(config, out=sys.stdout, err=sys.stderr):
+ basedir = config['basedir']
# This should always be called with an absolute Unicode basedir.
precondition(isinstance(basedir, unicode), basedir)
c.close()
print >>out, "Introducer created in %s" % quote_output(basedir)
+ return 0
subCommands = [
k.setServiceParent(application)
"""
-def create_key_generator(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_key_generator(config, out=sys.stdout, err=sys.stderr):
+ basedir = config['basedir']
# This should always be called with an absolute Unicode basedir.
precondition(isinstance(basedir, unicode), basedir)
so.stderr = stderr
so.stdin = stdin
- rc = 0
if command in create_dispatch:
- f = create_dispatch[command]
- for basedir in so.basedirs:
- rc = f(basedir, so, stdout, stderr) or rc
+ rc = create_dispatch[command](so, stdout, stderr)
elif command in startstop_node.dispatch:
rc = startstop_node.dispatch[command](so, stdout, stderr)
elif command in debug.dispatch:
class RunOptions(BasedirMixin, BaseOptions):
default_nodedir = u"."
- allow_multiple = False
optParameters = [
["node-directory", "d", None, "Specify the directory of the node to be run. [default, for 'tahoe run' only: current directory]"],
- ["multiple", "m", None, "['tahoe run' cannot accept multiple node directories]"],
]
-def do_start(basedir, opts, out=sys.stdout, err=sys.stderr):
+def start(opts, out=sys.stdout, err=sys.stderr):
+ basedir = opts['basedir']
print >>out, "STARTING", quote_output(basedir)
if not os.path.isdir(basedir):
print >>err, "%s does not look like a directory at all" % quote_output(basedir)
# we'll never get here. If application setup fails (e.g. ImportError),
# run() will raise an exception.
-def do_stop(basedir, out=sys.stdout, err=sys.stderr):
+def stop(config, out=sys.stdout, err=sys.stderr):
+ basedir = config['basedir']
print >>out, "STOPPING", quote_output(basedir)
pidfile = os.path.join(basedir, "twistd.pid")
if not os.path.exists(pidfile):
# we define rc=1 to mean "I think something is still running, sorry"
return 1
-def start(config, stdout, stderr):
- rc = 0
- for basedir in config['basedirs']:
- rc = do_start(basedir, config, stdout, stderr) or rc
- return rc
-
-def stop(config, stdout, stderr):
- rc = 0
- for basedir in config['basedirs']:
- rc = do_stop(basedir, stdout, stderr) or rc
- return rc
-
def restart(config, stdout, stderr):
- rc = 0
- for basedir in config['basedirs']:
- rc = do_stop(basedir, stdout, stderr) or rc
+ rc = stop(config, stdout, stderr)
if rc == 2:
print >>stderr, "ignoring couldn't-stop"
rc = 0
if rc:
print >>stderr, "not restarting"
return rc
- for basedir in config['basedirs']:
- rc = do_start(basedir, config, stdout, stderr) or rc
- return rc
+ return start(config, stdout, stderr)
def run(config, stdout, stderr):
from twisted.internet import reactor
from twisted.python import log, logfile
from allmydata import client
- basedir = config['basedirs'][0]
+ basedir = config['basedir']
precondition(isinstance(basedir, unicode), basedir)
if not os.path.isdir(basedir):
"""
-def create_stats_gatherer(basedir, config, out=sys.stdout, err=sys.stderr):
+def create_stats_gatherer(config, out=sys.stdout, err=sys.stderr):
+ basedir = config['basedir']
# This should always be called with an absolute Unicode basedir.
precondition(isinstance(basedir, unicode), basedir)
self.failUnless(os.path.exists(n3))
self.failUnless(os.path.exists(os.path.join(n3, tac)))
- # test the --multiple form
- n4 = os.path.join(basedir, command + "-n4")
- n5 = os.path.join(basedir, command + "-n5")
- argv = ["--quiet", command, "--multiple", n4, n5]
- rc, out, err = self.run_tahoe(argv)
- self.failUnlessEqual(err, "")
- self.failUnlessEqual(out, "")
- self.failUnlessEqual(rc, 0)
- self.failUnless(os.path.exists(n4))
- self.failUnless(os.path.exists(os.path.join(n4, tac)))
- self.failUnless(os.path.exists(n5))
- self.failUnless(os.path.exists(os.path.join(n5, tac)))
-
- # make sure it rejects too many arguments without --multiple
+ # make sure it rejects too many arguments
argv = [command, "basedir", "extraarg"]
self.failUnlessRaises(usage.UsageError,
runner.runner, argv,