[enh] Use hook_list and be more verbose in hook_callback

This commit is contained in:
Jérôme Lebleu 2014-12-04 18:45:20 +01:00
parent b977f11eda
commit 44df7f6351

33
hook.py
View file

@ -163,18 +163,31 @@ def hook_callback(action, args=None):
args -- Ordered list of arguments to pass to the script
"""
try: os.listdir(hook_folder + action)
except OSError: pass
else:
if args is None:
args = []
elif not isinstance(args, list):
args = [args]
result = { 'succeed': list(), 'failed': list() }
for hook in sorted(os.listdir(hook_folder + action)):
# Retrieve hooks by priority
hooks = hook_list(action, list_by='priority', show_info=True)['hooks']
if not hooks:
return result
# Format arguments
if args is None:
args = []
elif not isinstance(args, list):
args = [args]
# Iterate over hooks and execute them
for priority in sorted(hooks):
for name, info in iter(hooks[priority].items()):
try:
hook_exec(file=hook_folder + action +'/'+ hook, args=args)
except: pass
hook_exec(info['path'], args=args)
except:
logger.exception("error while executing hook '%s'",
info['path'])
result['failed'].append(name)
else:
result['succeed'].append(name)
return result
def hook_check(file):