6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2025-01-12 09:51:08 +00:00

Simplify quickstart by using save.callback

This commit is contained in:
Régis Behmo 2020-11-12 15:31:13 +01:00
parent b2fdaf604e
commit daabbdc3b6
3 changed files with 13 additions and 14 deletions

View File

@ -37,7 +37,7 @@ class YamlParamType(click.ParamType):
@click.option( @click.option(
"-s", "-s",
"--set", "--set",
"set_", "set_vars",
type=YamlParamType(), type=YamlParamType(),
multiple=True, multiple=True,
metavar="KEY=VAL", metavar="KEY=VAL",
@ -46,17 +46,18 @@ class YamlParamType(click.ParamType):
@click.option( @click.option(
"-U", "-U",
"--unset", "--unset",
"unset_vars",
multiple=True, multiple=True,
help="Remove a configuration value (can be used multiple times)", help="Remove a configuration value (can be used multiple times)",
) )
@click.pass_obj @click.pass_obj
def save(context, interactive, set_, unset): def save(context, interactive, set_vars, unset_vars):
config, defaults = interactive_config.load_all( config, defaults = interactive_config.load_all(
context.root, interactive=interactive context.root, interactive=interactive
) )
if set_: if set_vars:
tutor_config.merge(config, dict(set_), force=True) tutor_config.merge(config, dict(set_vars), force=True)
for key in unset: for key in unset_vars:
config.pop(key, None) config.pop(key, None)
tutor_config.save_config_file(context.root, config) tutor_config.save_config_file(context.root, config)
tutor_config.merge(config, defaults) tutor_config.merge(config, defaults)

View File

@ -3,13 +3,12 @@ from textwrap import indent
import click import click
from . import compose
from .context import Context
from .. import config as tutor_config from .. import config as tutor_config
from .. import env as tutor_env from .. import env as tutor_env
from .. import fmt from .. import fmt, utils
from .. import interactive as interactive_config from . import compose
from .. import utils from .config import save as config_save_command
from .context import Context
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
@ -53,9 +52,7 @@ def quickstart(context, non_interactive, pullimages_):
) )
click.echo(fmt.title("Interactive platform configuration")) click.echo(fmt.title("Interactive platform configuration"))
config = interactive_config.update(context.root, interactive=(not non_interactive)) config_save_command.callback(interactive=(not non_interactive), set_vars=[], unset_vars=[])
click.echo(fmt.title("Updating the current environment"))
tutor_env.save(context.root, config)
click.echo(fmt.title("Stopping any existing platform")) click.echo(fmt.title("Stopping any existing platform"))
compose.stop.callback([]) compose.stop.callback([])
click.echo(fmt.title("HTTPS certificates generation")) click.echo(fmt.title("HTTPS certificates generation"))
@ -68,6 +65,7 @@ def quickstart(context, non_interactive, pullimages_):
click.echo(fmt.title("Database creation and migrations")) click.echo(fmt.title("Database creation and migrations"))
compose.init.callback(limit=None) compose.init.callback(limit=None)
config = tutor_config.load(context.root)
fmt.echo_info( fmt.echo_info(
"""The Open edX platform is now running in detached mode """The Open edX platform is now running in detached mode
Your Open edX platform is ready and can be accessed at the following urls: Your Open edX platform is ready and can be accessed at the following urls:

View File

@ -231,7 +231,7 @@ def write_to(content, path):
if isinstance(content, bytes): if isinstance(content, bytes):
open_mode += "b" open_mode += "b"
utils.ensure_file_directory_exists(path) utils.ensure_file_directory_exists(path)
with open(path, open_mode, encoding='utf8') as of: with open(path, open_mode, encoding="utf8") as of:
of.write(content) of.write(content)