diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 1693ac27..958bc8c1 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1292,6 +1292,16 @@ hook: app: help: Scripts related to app will be removed + ### hook_info() + info: + action_help: Get information about a given hook + api: GET /hooks// + arguments: + action: + help: Action name + name: + help: Hook name + ### hook_list() list: action_help: List available hooks for an action diff --git a/lib/yunohost/hook.py b/lib/yunohost/hook.py index 1661edc8..d4c7962c 100644 --- a/lib/yunohost/hook.py +++ b/lib/yunohost/hook.py @@ -29,6 +29,7 @@ import re import json import errno import subprocess +from glob import iglob from moulinette.core import MoulinetteError from moulinette.utils.log import getActionLogger @@ -77,6 +78,46 @@ def hook_remove(app): except OSError: pass +def hook_info(action, name): + """ + Get information about a given hook + + Keyword argument: + action -- Action name + name -- Hook name + + """ + hooks = [] + priorities = set() + + # Search in custom folder first + for h in iglob('{:s}{:s}/*-{:s}'.format( + custom_hook_folder, action, name)): + priority, _ = _extract_filename_parts(os.path.basename(h)) + priorities.add(priority) + hooks.append({ + 'priority': priority, + 'path': h, + }) + # Append non-overwritten system hooks + for h in iglob('{:s}{:s}/*-{:s}'.format( + hook_folder, action, name)): + priority, _ = _extract_filename_parts(os.path.basename(h)) + if priority not in priorities: + hooks.append({ + 'priority': priority, + 'path': h, + }) + + if not hooks: + raise MoulinetteError(errno.EINVAL, m18n.n('hook_name_unknown', name)) + return { + 'action': action, + 'name': name, + 'hooks': hooks, + } + + def hook_list(action, list_by='name', show_info=False): """ List available hooks for an action @@ -194,7 +235,7 @@ def hook_callback(action, hooks=[], args=None): if key == n or key.startswith("%s_" % n) \ and key not in all_hooks: all_hooks.append(key) - + # Iterate over given hooks names list for n in all_hooks: try: