From 9009b3f9d35b6d2945926e0b144c553bf4af4850 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 5 Feb 2018 18:13:51 +0100 Subject: [PATCH] Handle disclaimers --- data/actionsmap/yunohost.yml | 4 +++- locales/en.json | 1 + src/yunohost/tools.py | 37 ++++++++++++++++++++++++------------ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 8eba45306..715a13504 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1599,7 +1599,9 @@ tools: --auto: help: automatic mode, won't run manual migrations, use it only if you know what you are doing action: store_true - + --accept-disclaimer: + help: accept disclaimers of migration (please read them before using this option) + action: store_true ### tools_migrations_state() state: diff --git a/locales/en.json b/locales/en.json index e5034cf81..b0c2ea3d2 100644 --- a/locales/en.json +++ b/locales/en.json @@ -238,6 +238,7 @@ "migrations_show_last_migration": "Last ran migration is {}", "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_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_enabled": "The server monitoring has been enabled", "monitor_glances_con_failed": "Unable to connect to Glances server", diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 2fd139318..9719f9223 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -765,7 +765,7 @@ def tools_migrations_list(pending=False, done=False): 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 """ @@ -825,21 +825,34 @@ def tools_migrations_migrate(target=None, skip=False, auto=False): else: # can't happen, this case is handle before 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 for migration in migrations: if not skip: - # If we are migrating in "automatic mode" (i.e. from debian - # configure during an upgrade of the package) but the migration - # 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)) - + logger.warn(m18n.n('migrations_show_currently_running_migration', + number=migration.number, name=migration.name)) try: if mode == "forward":