2019-01-22 20:25:04 +00:00
|
|
|
import click
|
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
from .. import config as tutor_config
|
|
|
|
from .. import env
|
2019-05-11 19:20:09 +00:00
|
|
|
from .. import exceptions
|
|
|
|
from .. import fmt
|
2019-06-05 17:45:22 +00:00
|
|
|
from .. import interactive as interactive_config
|
2019-05-11 19:20:09 +00:00
|
|
|
from .. import opts
|
2019-01-22 20:25:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.group(
|
2019-05-29 08:30:30 +00:00
|
|
|
name="config",
|
2019-01-22 20:25:04 +00:00
|
|
|
short_help="Configure Open edX",
|
2019-05-05 09:45:24 +00:00
|
|
|
help="""Configure Open edX and store configuration values in $TUTOR_ROOT/config.yml""",
|
2019-01-22 20:25:04 +00:00
|
|
|
)
|
2019-04-23 07:57:55 +00:00
|
|
|
def config_command():
|
2019-01-22 20:25:04 +00:00
|
|
|
pass
|
|
|
|
|
2019-04-19 22:02:47 +00:00
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
@click.command(help="Create and save configuration interactively")
|
2019-01-22 20:25:04 +00:00
|
|
|
@opts.root
|
2019-06-05 17:45:22 +00:00
|
|
|
@click.option("-i", "--interactive", is_flag=True, help="Run interactively")
|
2019-01-22 20:25:04 +00:00
|
|
|
@opts.key_value
|
2019-06-05 17:45:22 +00:00
|
|
|
def save(root, interactive, set_):
|
|
|
|
config, defaults = interactive_config.load_all(root, interactive=interactive)
|
2019-06-05 13:43:51 +00:00
|
|
|
if set_:
|
|
|
|
tutor_config.merge(config, dict(set_), force=True)
|
|
|
|
tutor_config.save(root, config)
|
|
|
|
tutor_config.merge(config, defaults)
|
|
|
|
env.save(root, config)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-04-19 22:02:47 +00:00
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
@click.command(help="Print the project root")
|
2019-01-22 20:25:04 +00:00
|
|
|
@opts.root
|
|
|
|
def printroot(root):
|
|
|
|
click.echo(root)
|
|
|
|
|
2019-04-19 22:02:47 +00:00
|
|
|
|
2019-03-18 21:38:13 +00:00
|
|
|
@click.command(help="Print a configuration value")
|
|
|
|
@opts.root
|
|
|
|
@click.argument("key")
|
|
|
|
def printvalue(root, key):
|
2019-06-05 13:43:51 +00:00
|
|
|
config = tutor_config.load(root)
|
2019-03-18 21:38:13 +00:00
|
|
|
try:
|
2019-06-05 13:43:51 +00:00
|
|
|
fmt.echo(config[key])
|
2019-03-18 21:38:13 +00:00
|
|
|
except KeyError:
|
|
|
|
raise exceptions.TutorError("Missing configuration value: {}".format(key))
|
|
|
|
|
2019-04-19 22:02:47 +00:00
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
config_command.add_command(save)
|
2019-04-23 07:57:55 +00:00
|
|
|
config_command.add_command(printroot)
|
|
|
|
config_command.add_command(printvalue)
|