From e20ec39cb218009ad047a485fe6049ce2ed4f709 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Mon, 14 Mar 2016 15:05:33 +0100 Subject: [PATCH] [enh] Set env. var YNH_APP_ARG_xxx for each manifest argument during install --- src/yunohost/app.py | 7 ++++++- src/yunohost/hook.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 5c610deeb..476f03a87 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -468,6 +468,11 @@ def app_install(auth, app, label=None, args=None): args_list = args_odict.values() args_list.append(app_id) + # Prepare env. var. to pass to script + env_dict = {} + for arg_name, arg_value in args_odict.items(): + env_dict[ "YNH_APP_ARG_%s" % arg_name ] = arg_value + # Create app directory app_setting_path = os.path.join(apps_setting_path, app_id) if os.path.exists(app_setting_path): @@ -497,7 +502,7 @@ def app_install(auth, app, label=None, args=None): os.system('cp %s/manifest.json %s' % (app_tmp_folder, app_setting_path)) os.system('cp -R %s/scripts %s' % (app_tmp_folder, app_setting_path)) try: - if hook_exec(app_tmp_folder + '/scripts/install', args_list) == 0: + if hook_exec(app_tmp_folder + '/scripts/install', args=args_list, env=env_dict) == 0: # Store app status with open(app_setting_path + '/status.json', 'w+') as f: json.dump(status, f) diff --git a/src/yunohost/hook.py b/src/yunohost/hook.py index 90a02f9f8..a61e3eb1c 100644 --- a/src/yunohost/hook.py +++ b/src/yunohost/hook.py @@ -307,7 +307,7 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False, env=None): cmd_args = '"{:s}"'.format('" "'.join(str(s) for s in args)) envcli = '' - if env is not None and isinstance(env, dict): + if env is not None: envcli = ' '.join([ '{key}="{val}"'.format(key=key, val=val) for key,val in env.items()]) # Construct command to execute