[fix] app_id is id in app list, not in yunohost

This commit is contained in:
Laurent Peuch 2018-09-08 02:45:18 +02:00
parent 8edc5c1ae3
commit b111c57aa5
2 changed files with 40 additions and 33 deletions

View file

@ -780,18 +780,18 @@ app:
### app_action_list() ### app_action_list()
list: list:
action_help: List app actions action_help: List app actions
api: GET /apps/<app_id>/actions api: GET /apps/<app>/actions
arguments: arguments:
app_id: app:
help: app id help: App name
### app_action_run() ### app_action_run()
run: run:
action_help: Run app action action_help: Run app action
api: PUT /apps/<app_id>/actions/<action> api: PUT /apps/<app>/actions/<action>
arguments: arguments:
app_id: app:
help: app id help: App name
action: action:
help: action id help: action id
-a: -a:
@ -805,18 +805,18 @@ app:
### app_config_show_panel() ### app_config_show_panel()
show-panel: show-panel:
action_help: show config panel for the application action_help: show config panel for the application
api: GET /apps/<app_id>/config-panel api: GET /apps/<app>/config-panel
arguments: arguments:
app_id: app:
help: App ID help: App name
### app_config_apply() ### app_config_apply()
apply: apply:
action_help: apply the new configuration action_help: apply the new configuration
api: POST /apps/<app_id>/config api: POST /apps/<app>/config
arguments: arguments:
app_id: app:
help: App ID help: App name
-a: -a:
full: --args full: --args
help: Serialized arguments for new configuration (i.e. "domain=domain.tld&path=/path") help: Serialized arguments for new configuration (i.e. "domain=domain.tld&path=/path")

View file

@ -1461,33 +1461,33 @@ def app_change_label(auth, app, new_label):
# actions todo list: # actions todo list:
# * docstring # * docstring
def app_action_list(app_id): def app_action_list(app):
logger.warning(m18n.n('experimental_feature')) logger.warning(m18n.n('experimental_feature'))
# this will take care of checking if the app is installed # this will take care of checking if the app is installed
app_info_dict = app_info(app_id) app_info_dict = app_info(app)
actions = os.path.join(APPS_SETTING_PATH, app_id, 'actions.json') actions = os.path.join(APPS_SETTING_PATH, app, 'actions.json')
return { return {
"app_id": app_id, "app": app,
"app_name": app_info_dict["name"], "app_name": app_info_dict["name"],
"actions": read_json(actions) if os.path.exists(actions) else [], "actions": read_json(actions) if os.path.exists(actions) else [],
} }
def app_action_run(app_id, action, args=None): def app_action_run(app, action, args=None):
logger.warning(m18n.n('experimental_feature')) logger.warning(m18n.n('experimental_feature'))
from yunohost.hook import hook_exec from yunohost.hook import hook_exec
import tempfile import tempfile
# will raise if action doesn't exist # will raise if action doesn't exist
actions = app_action_list(app_id)["actions"] actions = app_action_list(app)["actions"]
actions = {x["id"]: x for x in actions} actions = {x["id"]: x for x in actions}
if action not in actions: if action not in actions:
raise MoulinetteError(errno.EINVAL, "action '%s' not available for app '%s', available actions are: %s" % (action, app_id, ", ".join(actions.keys()))) raise MoulinetteError(errno.EINVAL, "action '%s' not available for app '%s', available actions are: %s" % (action, app, ", ".join(actions.keys())))
action_declaration = actions[action] action_declaration = actions[action]
@ -1508,9 +1508,9 @@ def app_action_run(app_id, action, args=None):
os.chmod(path, 700) os.chmod(path, 700)
if action_declaration.get("cwd"): if action_declaration.get("cwd"):
cwd = action_declaration["cwd"].replace("$app_id", app_id) cwd = action_declaration["cwd"].replace("$app", app_id)
else: else:
cwd = "/etc/yunohost/apps/" + app_id cwd = "/etc/yunohost/apps/" + app
retcode = hook_exec( retcode = hook_exec(
path, path,
@ -1521,7 +1521,7 @@ def app_action_run(app_id, action, args=None):
) )
if retcode not in action_declaration.get("accepted_return_codes", [0]): if retcode not in action_declaration.get("accepted_return_codes", [0]):
raise MoulinetteError(retcode, "Error while executing action '%s' of app '%s': return code %s" % (action, app_id, retcode)) raise MoulinetteError(retcode, "Error while executing action '%s' of app '%s': return code %s" % (action, app, retcode))
os.remove(path) os.remove(path)
@ -1531,27 +1531,31 @@ def app_action_run(app_id, action, args=None):
# Config panel todo list: # Config panel todo list:
# * docstrings # * docstrings
# * merge translations on the json once the workflow is in place # * merge translations on the json once the workflow is in place
def app_config_show_panel(app_id): def app_config_show_panel(app):
logger.warning(m18n.n('experimental_feature')) logger.warning(m18n.n('experimental_feature'))
from yunohost.hook import hook_exec from yunohost.hook import hook_exec
# this will take care of checking if the app is installed # this will take care of checking if the app is installed
app_info_dict = app_info(app_id) app_info_dict = app_info(app)
config_panel = os.path.join(APPS_SETTING_PATH, app, 'config_panel.json')
config_script = os.path.join(APPS_SETTING_PATH, app, 'scripts', 'config')
config_panel = os.path.join(APPS_SETTING_PATH, app_id, 'config_panel.json')
config_script = os.path.join(APPS_SETTING_PATH, app_id, 'scripts', 'config')
if not os.path.exists(config_panel) or not os.path.exists(config_script): if not os.path.exists(config_panel) or not os.path.exists(config_script):
return { return {
"app_id": app_id, "app_id": app_id,
"app": app,
"app_name": app_info_dict["name"], "app_name": app_info_dict["name"],
"config_panel": [], "config_panel": [],
} }
config_panel = read_json(config_panel) config_panel = read_json(config_panel)
env = {"YNH_APP_ID": app_id} env = {
"YNH_APP_ID": app,
}
parsed_values = {} parsed_values = {}
# I need to parse stdout to communicate between scripts because I can't # I need to parse stdout to communicate between scripts because I can't
@ -1608,23 +1612,24 @@ def app_config_show_panel(app_id):
return { return {
"app_id": app_id, "app_id": app_id,
"app": app,
"app_name": app_info_dict["name"], "app_name": app_info_dict["name"],
"config_panel": config_panel, "config_panel": config_panel,
} }
def app_config_apply(app_id, args): def app_config_apply(app, args):
logger.warning(m18n.n('experimental_feature')) logger.warning(m18n.n('experimental_feature'))
from yunohost.hook import hook_exec from yunohost.hook import hook_exec
installed = _is_installed(app_id) installed = _is_installed(app)
if not installed: if not installed:
raise MoulinetteError(errno.ENOPKG, raise MoulinetteError(errno.ENOPKG,
m18n.n('app_not_installed', app=app_id)) m18n.n('app_not_installed', app=app))
config_panel = os.path.join(APPS_SETTING_PATH, app_id, 'config_panel.json') config_panel = os.path.join(APPS_SETTING_PATH, app, 'config_panel.json')
config_script = os.path.join(APPS_SETTING_PATH, app_id, 'scripts', 'config') config_script = os.path.join(APPS_SETTING_PATH, app, 'scripts', 'config')
if not os.path.exists(config_panel) or not os.path.exists(config_script): if not os.path.exists(config_panel) or not os.path.exists(config_script):
# XXX real exception # XXX real exception
@ -1632,7 +1637,9 @@ def app_config_apply(app_id, args):
config_panel = read_json(config_panel) config_panel = read_json(config_panel)
env = {"YNH_APP_ID": app_id} env = {
"YNH_APP_ID": app,
}
args = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {} args = dict(urlparse.parse_qsl(args, keep_blank_values=True)) if args else {}
for tab in config_panel.get("panel", []): for tab in config_panel.get("panel", []):