From 999a61d2b28930cffb25857359961dd1028fba7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Fri, 2 Oct 2015 03:40:06 +0200 Subject: [PATCH] [enh] Allow to ignore backup hooks execution at creation --- data/actionsmap/yunohost.yml | 3 +++ lib/yunohost/backup.py | 18 ++++++++++++------ locales/en.json | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index a5f0827ba..546f7b504 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -594,6 +594,9 @@ backup: --hooks: help: List of backup hooks names to execute nargs: "*" + --ignore-hooks: + help: Do not execute backup hooks + action: store_true --apps: help: List of application names to backup nargs: "*" diff --git a/lib/yunohost/backup.py b/lib/yunohost/backup.py index dfa806e9c..27ec3e466 100644 --- a/lib/yunohost/backup.py +++ b/lib/yunohost/backup.py @@ -43,7 +43,8 @@ logger = getActionLogger('yunohost.backup') def backup_create(name=None, description=None, output_directory=None, - no_compress=False, hooks=[], apps=[], ignore_apps=False): + no_compress=False, ignore_hooks=False, hooks=[], + ignore_apps=False, apps=[]): """ Create a backup local archive @@ -53,6 +54,7 @@ def backup_create(name=None, description=None, output_directory=None, output_directory -- Output directory for the backup no_compress -- Do not create an archive file hooks -- List of backup hooks names to execute + ignore_hooks -- Do not execute backup hooks apps -- List of application names to backup ignore_apps -- Do not backup apps @@ -62,6 +64,11 @@ def backup_create(name=None, description=None, output_directory=None, tmp_dir = None + # Validate what to backup + if ignore_hooks and ignore_apps: + raise MoulinetteError(errno.EINVAL, + m18n.n('backup_action_required')) + # Validate and define backup name timestamp = int(time.time()) if not name: @@ -126,11 +133,10 @@ def backup_create(name=None, description=None, output_directory=None, } # Run system hooks - msignals.display(m18n.n('backup_running_hooks')) - hooks_ret = hook_callback('backup', hooks, args=[tmp_dir]) - - # Add hooks results to the info - info['hooks'] = hooks_ret['succeed'] + if not ignore_hooks: + msignals.display(m18n.n('backup_running_hooks')) + hooks_ret = hook_callback('backup', hooks, args=[tmp_dir]) + info['hooks'] = hooks_ret['succeed'] # Backup apps if not ignore_apps: diff --git a/locales/en.json b/locales/en.json index 85b9b08ed..651edabec 100644 --- a/locales/en.json +++ b/locales/en.json @@ -139,6 +139,7 @@ "packages_upgrade_failed" : "Unable to upgrade all packages", "system_upgraded" : "System successfully upgraded", + "backup_action_required" : "You must specify something to backup", "backup_output_directory_required" : "You must provide an output directory for the backup", "backup_output_directory_forbidden" : "Forbidden output directory", "backup_output_directory_not_empty" : "Output directory is not empty",