[enh] Add succeed hooks to the backup archive info

This commit is contained in:
Jérôme Lebleu 2015-10-01 02:49:51 +02:00
parent 4c37d8f273
commit cf0af877d9
2 changed files with 13 additions and 8 deletions

View file

@ -116,17 +116,21 @@ def backup_create(name=None, description=None, output_directory=None,
else:
os.system('chown -hR admin: %s' % tmp_dir)
# Run system hooks
msignals.display(m18n.n('backup_running_hooks'))
hook_callback('backup', hooks, args=[tmp_dir])
# Initialize backup info
info = {
'description': description or '',
'created_at': timestamp,
'apps': {},
'hooks': {},
}
# 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']
# Backup apps
if not ignore_apps:
from yunohost.app import app_info
@ -377,4 +381,5 @@ def backup_info(name):
time.gmtime(info['created_at'])),
'description': info['description'],
'apps': info['apps'],
'hooks': info['hooks'],
}

View file

@ -174,7 +174,7 @@ def hook_callback(action, hooks=[], args=None):
args -- Ordered list of arguments to pass to the script
"""
result = { 'succeed': list(), 'failed': list() }
result = { 'succeed': {}, 'failed': {} }
hooks_dict = {}
# Retrieve hooks
@ -209,15 +209,15 @@ def hook_callback(action, hooks=[], args=None):
# Iterate over hooks and execute them
for priority in sorted(hooks_dict):
for name, info in iter(hooks_dict[priority].items()):
state = 'succeed'
filename = '%s-%s' % (priority, name)
try:
hook_exec(info['path'], args=args)
except:
logger.exception("error while executing hook '%s'",
info['path'])
result['failed'].append(filename)
else:
result['succeed'].append(filename)
state = 'failed'
result[state][filename] = info['path']
return result