mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-22 14:22:25 +00:00
factor to use FilePath more
This commit is contained in:
parent
30b7be6f1d
commit
c7f4a1a157
@ -330,22 +330,15 @@ def _save_gridmanager_config(file_path, grid_manager):
|
|||||||
f.write("{}\n".format(data))
|
f.write("{}\n".format(data))
|
||||||
|
|
||||||
|
|
||||||
def _load_gridmanager_config(gm_config):
|
def _load_gridmanager_config(fp):
|
||||||
"""
|
"""
|
||||||
Loads a Grid Manager configuration and returns it (a dict) after
|
Loads a Grid Manager configuration and returns it (a dict) after
|
||||||
validating. Exceptions if the config can't be found, or has
|
validating. Exceptions if the config can't be found, or has
|
||||||
problems.
|
problems.
|
||||||
|
|
||||||
:param gm_config str: "-" (a single dash) for stdin or a filename
|
:param FilePath fp: None for stdin or a path to a Grid Manager
|
||||||
|
configuration directory
|
||||||
"""
|
"""
|
||||||
fp = None
|
|
||||||
if gm_config.strip() != '-':
|
|
||||||
fp = FilePath(gm_config.strip())
|
|
||||||
if not fp.exists():
|
|
||||||
raise RuntimeError(
|
|
||||||
"No such directory '{}'".format(gm_config)
|
|
||||||
)
|
|
||||||
|
|
||||||
if fp is None:
|
if fp is None:
|
||||||
gm = json.load(sys.stdin)
|
gm = json.load(sys.stdin)
|
||||||
else:
|
else:
|
||||||
@ -353,7 +346,7 @@ def _load_gridmanager_config(gm_config):
|
|||||||
gm = json.load(f)
|
gm = json.load(f)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return _GridManager.from_config(gm, gm_config)
|
return _GridManager.from_config(gm, fp or "<stdin>")
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise usage.UsageError(str(e))
|
raise usage.UsageError(str(e))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user