mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-30 01:38:55 +00:00
unify signature of all CLI dispatch functions
Now they all take a single 'config' argument, instead of some also taking stdout/stderr args.
This commit is contained in:
parent
57bed47495
commit
720aa1a51f
@ -1,6 +1,4 @@
|
||||
|
||||
import os, sys
|
||||
|
||||
import os
|
||||
from allmydata.scripts.common import BasedirOptions, NoDefaultBasedirOptions
|
||||
from allmydata.scripts.default_nodedir import _default_nodedir
|
||||
from allmydata.util.assertutil import precondition
|
||||
@ -129,7 +127,9 @@ def write_client_config(c, config):
|
||||
c.write("enabled = false\n")
|
||||
c.write("\n")
|
||||
|
||||
def create_node(config, out=sys.stdout, err=sys.stderr):
|
||||
def create_node(config):
|
||||
out = config.stdout
|
||||
err = config.stderr
|
||||
basedir = config['basedir']
|
||||
# This should always be called with an absolute Unicode basedir.
|
||||
precondition(isinstance(basedir, unicode), basedir)
|
||||
@ -162,12 +162,14 @@ def create_node(config, out=sys.stdout, err=sys.stderr):
|
||||
print >>out, " Please set [node]nickname= in tahoe.cfg"
|
||||
return 0
|
||||
|
||||
def create_client(config, out=sys.stdout, err=sys.stderr):
|
||||
def create_client(config):
|
||||
config['no-storage'] = True
|
||||
return create_node(config, out=out, err=err)
|
||||
return create_node(config)
|
||||
|
||||
|
||||
def create_introducer(config, out=sys.stdout, err=sys.stderr):
|
||||
def create_introducer(config):
|
||||
out = config.stdout
|
||||
err = config.stderr
|
||||
basedir = config['basedir']
|
||||
# This should always be called with an absolute Unicode basedir.
|
||||
precondition(isinstance(basedir, unicode), basedir)
|
||||
|
@ -128,20 +128,21 @@ def runner(argv,
|
||||
so.stdin = stdin
|
||||
|
||||
if command in create_dispatch:
|
||||
rc = create_dispatch[command](so, stdout, stderr)
|
||||
f = create_dispatch[command]
|
||||
elif command in startstop_node.dispatch:
|
||||
rc = startstop_node.dispatch[command](so, stdout, stderr)
|
||||
f = startstop_node.dispatch[command]
|
||||
elif command in debug.dispatch:
|
||||
rc = debug.dispatch[command](so)
|
||||
f = debug.dispatch[command]
|
||||
elif command in admin.dispatch:
|
||||
rc = admin.dispatch[command](so)
|
||||
f = admin.dispatch[command]
|
||||
elif command in cli.dispatch:
|
||||
rc = cli.dispatch[command](so)
|
||||
f = cli.dispatch[command]
|
||||
elif command in magic_folder_cli.dispatch:
|
||||
rc = magic_folder_cli.dispatch[command](so)
|
||||
f = magic_folder_cli.dispatch[command]
|
||||
else:
|
||||
raise usage.UsageError()
|
||||
|
||||
rc = f(so)
|
||||
return rc
|
||||
|
||||
|
||||
|
@ -99,7 +99,9 @@ def identify_node_type(basedir):
|
||||
return t
|
||||
return None
|
||||
|
||||
def start(config, out=sys.stdout, err=sys.stderr):
|
||||
def start(config):
|
||||
out = config.stdout
|
||||
err = config.stderr
|
||||
basedir = config['basedir']
|
||||
quoted_basedir = quote_local_unicode_path(basedir)
|
||||
print >>out, "STARTING", quoted_basedir
|
||||
@ -169,7 +171,9 @@ def start(config, out=sys.stdout, err=sys.stderr):
|
||||
# we should only reach here if --nodaemon or equivalent was used
|
||||
return 0
|
||||
|
||||
def stop(config, out=sys.stdout, err=sys.stderr):
|
||||
def stop(config):
|
||||
out = config.stdout
|
||||
err = config.stderr
|
||||
basedir = config['basedir']
|
||||
quoted_basedir = quote_local_unicode_path(basedir)
|
||||
print >>out, "STOPPING", quoted_basedir
|
||||
@ -227,23 +231,24 @@ def stop(config, out=sys.stdout, err=sys.stderr):
|
||||
# we define rc=1 to mean "I think something is still running, sorry"
|
||||
return 1
|
||||
|
||||
def restart(config, stdout, stderr):
|
||||
rc = stop(config, stdout, stderr)
|
||||
def restart(config):
|
||||
stderr = config.stderr
|
||||
rc = stop(config)
|
||||
if rc == 2:
|
||||
print >>stderr, "ignoring couldn't-stop"
|
||||
rc = 0
|
||||
if rc:
|
||||
print >>stderr, "not restarting"
|
||||
return rc
|
||||
return start(config, stdout, stderr)
|
||||
return start(config)
|
||||
|
||||
def run(config, stdout, stderr):
|
||||
def run(config):
|
||||
config.twistd_args = config.twistd_args + ("--nodaemon",)
|
||||
# Previously we would do the equivalent of adding ("--logfile",
|
||||
# "tahoesvc.log"), but that redirects stdout/stderr which is often
|
||||
# unhelpful, and the user can add that option explicitly if they want.
|
||||
|
||||
return start(config, stdout, stderr)
|
||||
return start(config)
|
||||
|
||||
|
||||
subCommands = [
|
||||
|
@ -1,4 +1,4 @@
|
||||
import os, sys
|
||||
import os
|
||||
from twisted.python import usage
|
||||
from allmydata.scripts.common import NoDefaultBasedirOptions
|
||||
from allmydata.scripts.create_node import write_tac
|
||||
@ -56,7 +56,8 @@ class CreateStatsGathererOptions(NoDefaultBasedirOptions):
|
||||
"""
|
||||
|
||||
|
||||
def create_stats_gatherer(config, out=sys.stdout, err=sys.stderr):
|
||||
def create_stats_gatherer(config):
|
||||
err = config.stderr
|
||||
basedir = config['basedir']
|
||||
# This should always be called with an absolute Unicode basedir.
|
||||
precondition(isinstance(basedir, unicode), basedir)
|
||||
|
Loading…
Reference in New Issue
Block a user