mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-04 04:04:10 +00:00
Parameterize argv to allmydata.scripts.runner.run
This commit is contained in:
parent
96b54e8f62
commit
d5bff458b6
@ -109,7 +109,7 @@ def parse_options(argv, config=None):
|
|||||||
def parse_or_exit_with_explanation(argv, stdout=sys.stdout):
|
def parse_or_exit_with_explanation(argv, stdout=sys.stdout):
|
||||||
config = Options()
|
config = Options()
|
||||||
try:
|
try:
|
||||||
parse_options(argv, config=config)
|
parse_options(argv[1:], config=config)
|
||||||
except usage.error as e:
|
except usage.error as e:
|
||||||
c = config
|
c = config
|
||||||
while hasattr(c, 'subOptions'):
|
while hasattr(c, 'subOptions'):
|
||||||
@ -119,7 +119,7 @@ def parse_or_exit_with_explanation(argv, stdout=sys.stdout):
|
|||||||
msg = e.args[0].decode(get_io_encoding())
|
msg = e.args[0].decode(get_io_encoding())
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = repr(e)
|
msg = repr(e)
|
||||||
print("%s: %s\n" % (sys.argv[0], quote_output(msg, quotemarks=False)), file=stdout)
|
print("%s: %s\n" % (argv[0], quote_output(msg, quotemarks=False)), file=stdout)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ def _maybe_enable_eliot_logging(options, reactor):
|
|||||||
# Pass on the options so we can dispatch the subcommand.
|
# Pass on the options so we can dispatch the subcommand.
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def run():
|
def run(argv=sys.argv):
|
||||||
# TODO(3035): Remove tox-check when error becomes a warning
|
# TODO(3035): Remove tox-check when error becomes a warning
|
||||||
if 'TOX_ENV_NAME' not in os.environ:
|
if 'TOX_ENV_NAME' not in os.environ:
|
||||||
assert sys.version_info < (3,), u"Tahoe-LAFS does not run under Python 3. Please use Python 2.7.x."
|
assert sys.version_info < (3,), u"Tahoe-LAFS does not run under Python 3. Please use Python 2.7.x."
|
||||||
@ -180,19 +180,19 @@ def run():
|
|||||||
from allmydata.windows.fixups import initialize
|
from allmydata.windows.fixups import initialize
|
||||||
initialize()
|
initialize()
|
||||||
# doesn't return: calls sys.exit(rc)
|
# doesn't return: calls sys.exit(rc)
|
||||||
task.react(_run_with_reactor)
|
task.react(_run_with_reactor, argv)
|
||||||
|
|
||||||
|
|
||||||
def _setup_coverage(reactor):
|
def _setup_coverage(reactor, argv):
|
||||||
"""
|
"""
|
||||||
Arrange for coverage to be collected if the 'coverage' package is
|
Arrange for coverage to be collected if the 'coverage' package is
|
||||||
installed
|
installed
|
||||||
"""
|
"""
|
||||||
# can we put this _setup_coverage call after we hit
|
# can we put this _setup_coverage call after we hit
|
||||||
# argument-parsing?
|
# argument-parsing?
|
||||||
if '--coverage' not in sys.argv:
|
if '--coverage' not in argv:
|
||||||
return
|
return
|
||||||
sys.argv.remove('--coverage')
|
argv.remove('--coverage')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import coverage
|
import coverage
|
||||||
@ -223,11 +223,11 @@ def _setup_coverage(reactor):
|
|||||||
reactor.addSystemEventTrigger('after', 'shutdown', write_coverage_data)
|
reactor.addSystemEventTrigger('after', 'shutdown', write_coverage_data)
|
||||||
|
|
||||||
|
|
||||||
def _run_with_reactor(reactor):
|
def _run_with_reactor(reactor, argv):
|
||||||
|
|
||||||
_setup_coverage(reactor)
|
_setup_coverage(reactor, argv)
|
||||||
|
|
||||||
d = defer.maybeDeferred(parse_or_exit_with_explanation, sys.argv[1:])
|
d = defer.maybeDeferred(parse_or_exit_with_explanation, argv)
|
||||||
d.addCallback(_maybe_enable_eliot_logging, reactor)
|
d.addCallback(_maybe_enable_eliot_logging, reactor)
|
||||||
d.addCallback(dispatch)
|
d.addCallback(dispatch)
|
||||||
def _show_exception(f):
|
def _show_exception(f):
|
||||||
|
@ -524,7 +524,7 @@ class CLI(CLITestMixin, unittest.TestCase):
|
|||||||
ns.sys_exit_called = True
|
ns.sys_exit_called = True
|
||||||
self.failUnlessEqual(exitcode, 1)
|
self.failUnlessEqual(exitcode, 1)
|
||||||
|
|
||||||
def fake_react(f):
|
def fake_react(f, *args):
|
||||||
reactor = Mock()
|
reactor = Mock()
|
||||||
d = f(reactor)
|
d = f(reactor)
|
||||||
# normally this Deferred would be errbacked with SystemExit, but
|
# normally this Deferred would be errbacked with SystemExit, but
|
||||||
@ -534,12 +534,15 @@ class CLI(CLITestMixin, unittest.TestCase):
|
|||||||
|
|
||||||
patcher = MonkeyPatcher((runner, 'parse_or_exit_with_explanation',
|
patcher = MonkeyPatcher((runner, 'parse_or_exit_with_explanation',
|
||||||
call_parse_or_exit),
|
call_parse_or_exit),
|
||||||
(sys, 'argv', ["tahoe"]),
|
|
||||||
(sys, 'exit', call_sys_exit),
|
(sys, 'exit', call_sys_exit),
|
||||||
(sys, 'stderr', stderr),
|
(sys, 'stderr', stderr),
|
||||||
(task, 'react', fake_react),
|
(task, 'react', fake_react),
|
||||||
)
|
)
|
||||||
patcher.runWithPatches(runner.run)
|
patcher.runWithPatches(
|
||||||
|
lambda: runner.run(
|
||||||
|
["tahoe"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
self.failUnless(ns.parse_called)
|
self.failUnless(ns.parse_called)
|
||||||
self.failUnless(ns.sys_exit_called)
|
self.failUnless(ns.sys_exit_called)
|
||||||
|
@ -81,7 +81,7 @@ def run_cli_bytes(verb, *args, **kwargs):
|
|||||||
args=args,
|
args=args,
|
||||||
nodeargs=nodeargs,
|
nodeargs=nodeargs,
|
||||||
)
|
)
|
||||||
argv = nodeargs + [verb] + list(args)
|
argv = ["tahoe"] + nodeargs + [verb] + list(args)
|
||||||
stdin = kwargs.get("stdin", "")
|
stdin = kwargs.get("stdin", "")
|
||||||
if encoding is None:
|
if encoding is None:
|
||||||
# The original behavior, the Python 2 behavior, is to accept either
|
# The original behavior, the Python 2 behavior, is to accept either
|
||||||
|
Loading…
Reference in New Issue
Block a user