6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-12 14:17:46 +00:00

Improve output of environment upgrade

This commit is contained in:
Silvio Tomatis 2019-04-18 16:11:40 +02:00 committed by Régis Behmo
parent a2b098c1f0
commit 8cbab483ca

View File

@ -76,22 +76,27 @@ def load(root):
save_config(root, config) save_config(root, config)
load_defaults(config) load_defaults(config)
if not env.is_up_to_date(root): if not env.is_up_to_date(root):
should_update_env = True should_update_env = True
if os.isatty(sys.stdin.fileno()): message = (
# Interactive mode: ask the user permission to proceed
click.confirm(fmt.alert(
"The current environment stored at {} is not up-to-date: it is at " "The current environment stored at {} is not up-to-date: it is at "
"v{} while the 'tutor' binary is at v{}. The environment will be " "v{} while the 'tutor' binary is at v{}.".format(
"upgraded now. Any change you might have made will be overwritten.".format(
env.base_dir(root), env.version(root), __version__ env.base_dir(root), env.version(root), __version__
) )
), abort=True) )
if os.isatty(sys.stdin.fileno()):
# Interactive mode: ask the user permission to proceed
confirmation_msg = ("If you choose Y The environment will be "
"upgraded now.\nAny change you might have made will be overwritten.\nProceed?")
click.confirm(fmt.alert(message + '\n' + confirmation_msg), abort=True)
elif os.environ.get('TUTOR_OVERWRITE_ENV'): elif os.environ.get('TUTOR_OVERWRITE_ENV'):
pass # Non-interactive mode with environment variable authorizing us to go pass # Non-interactive mode with environment variable authorizing us to go
else: else:
raise click.Abort # Non-interactive mode with no authorization: abort # Non-interactive mode with no authorization: abort
post_message = ("Set the TUTOR_OVERWRITE_ENV variable "
"to allow tutor to rewrite the environment"
"in a non-interactive run.")
raise click.UsageError(message + "\n" + post_message)
if should_update_env: if should_update_env:
save_env(root, config) save_env(root, config)