From cddfc94666980f3eb28346d53ec4468c44cd676d Mon Sep 17 00:00:00 2001 From: Kload Date: Fri, 22 Nov 2013 15:29:07 +0100 Subject: [PATCH] Pass args to app install --- action_map.yml | 8 ++++++-- yunohost_app.py | 15 +++++++++++++-- yunohost_hook.py | 6 +++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/action_map.yml b/action_map.yml index 251005b6..e3cbc766 100644 --- a/action_map.yml +++ b/action_map.yml @@ -283,7 +283,7 @@ app: full: --user help: Allowed app map for a user pattern: '^[a-z0-9_]+$' - + ### app_install() TODO: Write help install: @@ -294,6 +294,10 @@ app: help: App to install -l: full: --label + help: Custom name for the app + -a: + full: --args + help: Serialize arguments for app installation ### app_remove() TODO: Write help remove: @@ -372,7 +376,7 @@ app: ssowatconf: action_help: Regenerate SSOwat configuration file api: PUT /ssowatconf - + ### app_addaccess() TODO: Write help addaccess: action_help: Grant access right to users (everyone by default) diff --git a/yunohost_app.py b/yunohost_app.py index d63a13e6..1ffe6130 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -32,6 +32,7 @@ import yaml import time import re import socket +import urlparse from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate from yunohost_domain import domain_list, domain_add from yunohost_user import user_info, user_list @@ -331,13 +332,14 @@ def app_upgrade(app, url=None, file=None): win_msg(_("Upgrade complete")) -def app_install(app, label=None): +def app_install(app, label=None, args=None): """ Install apps Keyword argument: label app -- App to install + args -- Serialize arguments of installation """ #TODO: Create tool for nginx (check path availability & stuff) @@ -398,8 +400,16 @@ def app_install(app, label=None): app_setting(app_id, 'label', manifest['name']) os.system('chown -R admin: '+ app_tmp_folder) + + try: + if args is None: + args = '' + args_dict = dict(urlparse.parse_qsl(args)) + except: + args_dict = {} + # Execute App install script - if hook_exec(app_tmp_folder + '/scripts/install') == 0: + if hook_exec(app_tmp_folder + '/scripts/install', args_dict) == 0: # Move scripts and manifest to the right place os.system('mv "'+ app_tmp_folder +'/manifest.json" "'+ app_tmp_folder +'/scripts" '+ app_setting_path) shutil.rmtree(app_tmp_folder) @@ -410,6 +420,7 @@ def app_install(app, label=None): else: #TODO: display script fail messages shutil.rmtree(app_setting_path) + shutil.rmtree(app_tmp_folder) raise YunoHostError(1, _("Installation failed")) diff --git a/yunohost_hook.py b/yunohost_hook.py index 918055b1..6929a764 100644 --- a/yunohost_hook.py +++ b/yunohost_hook.py @@ -42,9 +42,9 @@ def hook_add(action, file): """ try: os.listdir(hook_folder + action) except OSError: os.makedirs(hook_folder + action) - + os.system('cp '+ file +' '+ hook_folder + action) - + def hook_callback(action): """ @@ -109,7 +109,7 @@ def hook_exec(file, args=None): elif os.isatty(1) and 'ask' in arg: arg_list.append(raw_input(colorize(arg['ask']['en'] + ': ', 'cyan'))) #TODO: I18n else: - raise YunoHostError(22, _("Missing arguments") + ': ' + arg_name) + raise YunoHostError(22, _("Missing arguments") + ': ' + arg['name']) file_path = "./" if "/" in file and file[0:2] != file_path: