Pass args to app install

This commit is contained in:
Kload 2013-11-22 15:29:07 +01:00
parent 9052d3be9f
commit cddfc94666
3 changed files with 22 additions and 7 deletions

View file

@ -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)

View file

@ -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"))

View file

@ -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: