Handle disclaimers

This commit is contained in:
Alexandre Aubin 2018-02-05 18:13:51 +01:00
parent c8b1d7e2c3
commit 9009b3f9d3
3 changed files with 29 additions and 13 deletions

View file

@ -1599,7 +1599,9 @@ tools:
--auto: --auto:
help: automatic mode, won't run manual migrations, use it only if you know what you are doing help: automatic mode, won't run manual migrations, use it only if you know what you are doing
action: store_true action: store_true
--accept-disclaimer:
help: accept disclaimers of migration (please read them before using this option)
action: store_true
### tools_migrations_state() ### tools_migrations_state()
state: state:

View file

@ -238,6 +238,7 @@
"migrations_show_last_migration": "Last ran migration is {}", "migrations_show_last_migration": "Last ran migration is {}",
"migrations_skip_migration": "Skipping migration {number} {name}...", "migrations_skip_migration": "Skipping migration {number} {name}...",
"migrations_to_be_ran_manually": "Migration {number} {name} has to be ran manually. Please go to Tools > Migrations on the webadmin, or run `yunohost tools migrations migrate`.", "migrations_to_be_ran_manually": "Migration {number} {name} has to be ran manually. Please go to Tools > Migrations on the webadmin, or run `yunohost tools migrations migrate`.",
"migrations_need_to_accept_disclaimer": "To run the migration {number} {name}, your must accept the following disclaimer:\n---\n{disclaimer}\n---\nIf you accept to run the migration, please re-run the command with the option --accept-disclaimer.",
"monitor_disabled": "The server monitoring has been disabled", "monitor_disabled": "The server monitoring has been disabled",
"monitor_enabled": "The server monitoring has been enabled", "monitor_enabled": "The server monitoring has been enabled",
"monitor_glances_con_failed": "Unable to connect to Glances server", "monitor_glances_con_failed": "Unable to connect to Glances server",

View file

@ -765,7 +765,7 @@ def tools_migrations_list(pending=False, done=False):
return {"migrations": migrations} return {"migrations": migrations}
def tools_migrations_migrate(target=None, skip=False, auto=False): def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclaimer=False):
""" """
Perform migrations Perform migrations
""" """
@ -825,21 +825,34 @@ def tools_migrations_migrate(target=None, skip=False, auto=False):
else: # can't happen, this case is handle before else: # can't happen, this case is handle before
raise Exception() raise Exception()
# If we are migrating in "automatic mode" (i.e. from debian
# configure during an upgrade of the package) but we are asked to run
# migrations is to be ran manually by the user
manual_migrations = [m for m in migrations if m.mode == "manual"]
if auto and manual_migrations:
for m in manual_migrations:
logger.warn(m18n.n('migrations_to_be_ran_manually',
number=m.number,
name=m.name))
return
# If some migrations have disclaimers, require the --accept-disclaimer
# option
migrations_with_disclaimer = [m for m in migrations if m.disclaimer]
if not accept_disclaimer and migrations_with_disclaimer:
for m in migrations_with_disclaimer:
logger.warn(m18n.n('migrations_need_to_accept_disclaimer',
number=m.number,
name=m.name,
disclaimer=m.disclaimer))
return
# effectively run selected migrations # effectively run selected migrations
for migration in migrations: for migration in migrations:
if not skip: if not skip:
# If we are migrating in "automatic mode" (i.e. from debian logger.warn(m18n.n('migrations_show_currently_running_migration',
# configure during an upgrade of the package) but the migration number=migration.number, name=migration.name))
# is to be ran manually by the user
if auto and migration.mode == "manual":
logger.warn(m18n.n('migrations_to_be_ran_manually',
number=migration.number, name=migration.name))
break
else:
logger.warn(m18n.n('migrations_show_currently_running_migration',
number=migration.number, name=migration.name))
try: try:
if mode == "forward": if mode == "forward":