def run(command, conf=None, tutorial=False, pdb=False, **args):
"""Main entry point for a direct call from Python
Example usage:
>>> from yam import run
>>> run(conf='conf.json')
:param command: if ``'create'`` the example configuration is created,
optionally the tutorial data files are downloaded
For all other commands this function loads the configuration
and construct the arguments which are passed to `run2()`
All args correspond to the respective command line and
configuration options.
See the example configuration file for help and possible arguments.
Options in args can overwrite the configuration from the file.
E.g. ``run(conf='conf.json', bla='bla')`` will set bla configuration
value to ``'bla'``.
"""
if pdb:
import traceback, pdb
def info(type, value, tb):
traceback.print_exception(type, value, tb)
print
# ...then start the debugger in post-mortem mode.
pdb.pm()
sys.excepthook = info
if conf in ('None', 'none', 'null', ''):
conf = None
# Copy example files if create_config or tutorial
if command == 'create':
if conf is None:
conf = 'conf.json'
create_config(conf, tutorial=tutorial)
return
# Parse config file
if conf:
try:
with open(conf) as f:
conf = json.load(f, cls=ConfigJSONDecoder)
except ValueError as ex:
msg = 'Error while parsing the configuration: %s' % ex
raise ConfigError(msg)
except IOError as ex:
raise ConfigError(ex)
# Populate args with conf, but prefer args
conf.update(args)
args = conf
run2(command, **args)
评论列表
文章目录