2019-06-05 13:43:51 +00:00
|
|
|
import click
|
|
|
|
|
|
|
|
from . import config as tutor_config
|
|
|
|
from . import env
|
2019-12-24 16:22:12 +00:00
|
|
|
from . import exceptions
|
2019-06-05 13:43:51 +00:00
|
|
|
from . import fmt
|
|
|
|
from .__about__ import __version__
|
|
|
|
|
|
|
|
|
2019-06-05 17:45:22 +00:00
|
|
|
def update(root, interactive=True):
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
|
|
|
Load and save the configuration.
|
|
|
|
"""
|
2019-06-05 17:45:22 +00:00
|
|
|
config, defaults = load_all(root, interactive=interactive)
|
2020-02-27 16:14:00 +00:00
|
|
|
tutor_config.save_config_file(root, config)
|
2019-06-05 13:43:51 +00:00
|
|
|
tutor_config.merge(config, defaults)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
2019-06-05 17:45:22 +00:00
|
|
|
def load_all(root, interactive=True):
|
2019-06-05 13:43:51 +00:00
|
|
|
"""
|
|
|
|
Load configuration and interactively ask questions to collect param values from the user.
|
|
|
|
"""
|
2019-12-24 16:22:12 +00:00
|
|
|
config, defaults = tutor_config.load_all(root)
|
2019-06-05 17:45:22 +00:00
|
|
|
if interactive:
|
2019-06-05 13:43:51 +00:00
|
|
|
ask_questions(config, defaults)
|
|
|
|
return config, defaults
|
|
|
|
|
|
|
|
|
|
|
|
def ask_questions(config, defaults):
|
2020-08-19 05:52:07 +00:00
|
|
|
run_for_prod = config.get("LMS_HOST") != "local.overhang.io"
|
2019-12-24 16:22:12 +00:00
|
|
|
run_for_prod = click.confirm(
|
|
|
|
fmt.question(
|
|
|
|
"Are you configuring a production platform? Type 'n' if you are just testing Tutor on your local computer"
|
|
|
|
),
|
|
|
|
prompt_suffix=" ",
|
2020-08-19 05:52:07 +00:00
|
|
|
default=run_for_prod,
|
2019-12-24 16:22:12 +00:00
|
|
|
)
|
|
|
|
if not run_for_prod:
|
|
|
|
dev_values = {
|
|
|
|
"LMS_HOST": "local.overhang.io",
|
|
|
|
"CMS_HOST": "studio.local.overhang.io",
|
2020-09-17 10:53:14 +00:00
|
|
|
"ENABLE_HTTPS": False,
|
2019-12-24 16:22:12 +00:00
|
|
|
}
|
|
|
|
fmt.echo_info(
|
|
|
|
"""As you are not running this platform in production, we automatically set the following configuration values:"""
|
|
|
|
)
|
|
|
|
for k, v in dev_values.items():
|
|
|
|
config[k] = v
|
|
|
|
fmt.echo_info(" {} = {}".format(k, v))
|
|
|
|
|
|
|
|
if run_for_prod:
|
|
|
|
ask("Your website domain name for students (LMS)", "LMS_HOST", config, defaults)
|
|
|
|
if "localhost" in config["LMS_HOST"]:
|
|
|
|
raise exceptions.TutorError(
|
|
|
|
"You may not use 'localhost' as the LMS domain name. To run a local platform for testing purposes you should answer 'n' to the previous question."
|
|
|
|
)
|
|
|
|
ask("Your website domain name for teachers (CMS)", "CMS_HOST", config, defaults)
|
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
ask("Your platform name/title", "PLATFORM_NAME", config, defaults)
|
|
|
|
ask("Your public contact email address", "CONTACT_EMAIL", config, defaults)
|
|
|
|
ask_choice(
|
|
|
|
"The default language code for the platform",
|
|
|
|
"LANGUAGE_CODE",
|
|
|
|
config,
|
|
|
|
defaults,
|
|
|
|
[
|
|
|
|
"en",
|
|
|
|
"am",
|
|
|
|
"ar",
|
|
|
|
"az",
|
|
|
|
"bg-bg",
|
|
|
|
"bn-bd",
|
|
|
|
"bn-in",
|
|
|
|
"bs",
|
|
|
|
"ca",
|
|
|
|
"ca@valencia",
|
|
|
|
"cs",
|
|
|
|
"cy",
|
|
|
|
"da",
|
|
|
|
"de-de",
|
|
|
|
"el",
|
|
|
|
"en-uk",
|
|
|
|
"en@lolcat",
|
|
|
|
"en@pirate",
|
|
|
|
"es-419",
|
|
|
|
"es-ar",
|
|
|
|
"es-ec",
|
|
|
|
"es-es",
|
|
|
|
"es-mx",
|
|
|
|
"es-pe",
|
|
|
|
"et-ee",
|
|
|
|
"eu-es",
|
|
|
|
"fa",
|
|
|
|
"fa-ir",
|
|
|
|
"fi-fi",
|
|
|
|
"fil",
|
|
|
|
"fr",
|
|
|
|
"gl",
|
|
|
|
"gu",
|
|
|
|
"he",
|
|
|
|
"hi",
|
|
|
|
"hr",
|
|
|
|
"hu",
|
|
|
|
"hy-am",
|
|
|
|
"id",
|
|
|
|
"it-it",
|
|
|
|
"ja-jp",
|
|
|
|
"kk-kz",
|
|
|
|
"km-kh",
|
|
|
|
"kn",
|
|
|
|
"ko-kr",
|
|
|
|
"lt-lt",
|
|
|
|
"ml",
|
|
|
|
"mn",
|
|
|
|
"mr",
|
|
|
|
"ms",
|
|
|
|
"nb",
|
|
|
|
"ne",
|
|
|
|
"nl-nl",
|
|
|
|
"or",
|
|
|
|
"pl",
|
|
|
|
"pt-br",
|
|
|
|
"pt-pt",
|
|
|
|
"ro",
|
|
|
|
"ru",
|
|
|
|
"si",
|
|
|
|
"sk",
|
|
|
|
"sl",
|
|
|
|
"sq",
|
|
|
|
"sr",
|
|
|
|
"sv",
|
|
|
|
"sw",
|
|
|
|
"ta",
|
|
|
|
"te",
|
|
|
|
"th",
|
|
|
|
"tr-tr",
|
|
|
|
"uk",
|
|
|
|
"ur",
|
|
|
|
"vi",
|
|
|
|
"uz",
|
|
|
|
"zh-cn",
|
|
|
|
"zh-hk",
|
|
|
|
"zh-tw",
|
|
|
|
],
|
|
|
|
)
|
2019-12-24 16:22:12 +00:00
|
|
|
if run_for_prod:
|
|
|
|
ask_bool(
|
|
|
|
(
|
|
|
|
"Activate SSL/TLS certificates for HTTPS access? Important note:"
|
|
|
|
" this will NOT work in a development environment."
|
|
|
|
),
|
2020-09-17 10:53:14 +00:00
|
|
|
"ENABLE_HTTPS",
|
2019-12-24 16:22:12 +00:00
|
|
|
config,
|
|
|
|
defaults,
|
|
|
|
)
|
2019-06-05 13:43:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ask(question, key, config, defaults):
|
|
|
|
default = env.render_str(config, config.get(key, defaults[key]))
|
|
|
|
config[key] = click.prompt(
|
|
|
|
fmt.question(question), prompt_suffix=" ", default=default, show_default=True
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def ask_bool(question, key, config, defaults):
|
|
|
|
default = config.get(key, defaults[key])
|
|
|
|
config[key] = click.confirm(
|
|
|
|
fmt.question(question), prompt_suffix=" ", default=default
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def ask_choice(question, key, config, defaults, choices):
|
|
|
|
default = config.get(key, defaults[key])
|
|
|
|
answer = click.prompt(
|
|
|
|
fmt.question(question),
|
|
|
|
type=click.Choice(choices),
|
|
|
|
prompt_suffix=" ",
|
|
|
|
default=default,
|
|
|
|
show_choices=False,
|
|
|
|
)
|
|
|
|
config[key] = answer
|