mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add a hook_info action
This commit is contained in:
parent
c16203bd2a
commit
369dec6775
2 changed files with 52 additions and 1 deletions
|
@ -1292,6 +1292,16 @@ hook:
|
||||||
app:
|
app:
|
||||||
help: Scripts related to app will be removed
|
help: Scripts related to app will be removed
|
||||||
|
|
||||||
|
### hook_info()
|
||||||
|
info:
|
||||||
|
action_help: Get information about a given hook
|
||||||
|
api: GET /hooks/<action>/<name>
|
||||||
|
arguments:
|
||||||
|
action:
|
||||||
|
help: Action name
|
||||||
|
name:
|
||||||
|
help: Hook name
|
||||||
|
|
||||||
### hook_list()
|
### hook_list()
|
||||||
list:
|
list:
|
||||||
action_help: List available hooks for an action
|
action_help: List available hooks for an action
|
||||||
|
|
|
@ -29,6 +29,7 @@ import re
|
||||||
import json
|
import json
|
||||||
import errno
|
import errno
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from glob import iglob
|
||||||
|
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
|
@ -77,6 +78,46 @@ def hook_remove(app):
|
||||||
except OSError: pass
|
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):
|
def hook_list(action, list_by='name', show_info=False):
|
||||||
"""
|
"""
|
||||||
List available hooks for an action
|
List available hooks for an action
|
||||||
|
|
Loading…
Add table
Reference in a new issue