diff --git a/helpers/helpers.v1.d/config b/helpers/helpers.v1.d/config index eae4d928d..e36897d82 100644 --- a/helpers/helpers.v1.d/config +++ b/helpers/helpers.v1.d/config @@ -126,60 +126,9 @@ _ynh_app_config_apply_one() { fi fi } + _ynh_app_config_get() { - # From settings - local lines - lines=$( - python3 <" in bind_section: - bind_section = bind_section + bind_panel_file - else: - bind_section = regex + bind_section + bind_panel_file - - for name, param in section.items(): - if not isinstance(param, dict): - continue - - bind = param.get('bind') - - if not bind: - if bind_section: - bind = bind_section - else: - bind = 'settings' - elif bind[-1] == ":" and bind_section and ":" in bind_section: - regex, bind_file = bind_section.split(":") - if ">" in bind: - bind = bind + bind_file - else: - bind = regex + bind + bind_file - if bind == "settings" and param.get('type', 'string') == 'file': - bind = 'null' - - print('|'.join([ - name, - param.get('type', 'string'), - bind - ])) -EOL - ) - for line in $lines; do + for line in $YNH_APP_CONFIG_PANEL_OPTIONS_TYPES_AND_BINDS; do # Split line into short_setting, type and bind IFS='|' read short_setting type bind <<<"$line" binds[${short_setting}]="$bind" @@ -188,7 +137,6 @@ EOL formats[${short_setting}]="" ynh_app_config_get_one $short_setting $type $bind done - } _ynh_app_config_apply() { diff --git a/helpers/helpers.v2.1.d/config b/helpers/helpers.v2.1.d/config index 2c708209b..b853d44d8 100644 --- a/helpers/helpers.v2.1.d/config +++ b/helpers/helpers.v2.1.d/config @@ -135,60 +135,9 @@ _ynh_app_config_apply_one() { fi fi } + _ynh_app_config_get() { - # From settings - local lines - lines=$( - python3 <" in bind_section: - bind_section = bind_section + bind_panel_file - else: - bind_section = regex + bind_section + bind_panel_file - - for name, param in section.items(): - if not isinstance(param, dict): - continue - - bind = param.get('bind') - - if not bind: - if bind_section: - bind = bind_section - else: - bind = 'settings' - elif bind[-1] == ":" and bind_section and ":" in bind_section: - regex, bind_file = bind_section.split(":") - if ">" in bind: - bind = bind + bind_file - else: - bind = regex + bind + bind_file - if bind == "settings" and param.get('type', 'string') == 'file': - bind = 'null' - - print('|'.join([ - name, - param.get('type', 'string'), - bind - ])) -EOL - ) - for line in $lines; do + for line in $YNH_APP_CONFIG_PANEL_OPTIONS_TYPES_AND_BINDS; do # Split line into short_setting, type and bind IFS='|' read short_setting type bind <<<"$line" binds[${short_setting}]="$bind" @@ -197,7 +146,6 @@ EOL formats[${short_setting}]="" ynh_app_config_get_one $short_setting $type $bind done - } _ynh_app_config_apply() { diff --git a/src/app.py b/src/app.py index 6abe37db2..903e573b9 100644 --- a/src/app.py +++ b/src/app.py @@ -1998,6 +1998,7 @@ ynh_app_config_run $1 "install_dir": settings.get("install_dir", ""), "YNH_APP_BASEDIR": os.path.join(APPS_SETTING_PATH, app), "YNH_APP_PACKAGING_FORMAT": str(manifest["packaging_format"]), + "YNH_APP_CONFIG_PANEL_OPTIONS_TYPES_AND_BINDS": self._dump_options_types_and_binds(), } ) app_script_env = _make_environment_for_app_script(app) @@ -2006,6 +2007,7 @@ ynh_app_config_run $1 app_script_env.update(env) env = app_script_env + ret, values = hook_exec(config_script, args=[action], env=env) if ret != 0: if action == "show": @@ -2020,14 +2022,56 @@ ynh_app_config_run $1 ret = super()._get_config_panel() - settings = _get_app_settings(self.entity) - - for _, _, option in self._iterate(): - if "bind" in option: - option["bind"] = _hydrate_app_template(option["bind"], settings) + self._compute_binds() return ret + def _compute_binds(self): + """ + This compute the 'bind' statement for every option + In particular to handle __FOOBAR__ syntax + and to handle the fact that bind statements may be defined panel-wide or section-wide + """ + + settings = _get_app_settings(self.entity) + + for panel, section, option in self._iterate(): + + bind_panel = panel.get('bind') + + bind_section = section.get('bind') + if not bind_section: + bind_section = bind_panel + elif bind_section[-1] == ":" and bind_panel and ":" in bind_panel: + selector, bind_panel_file = bind_panel.split(":") + if ">" in bind_section: + bind_section = bind_section + bind_panel_file + else: + bind_section = selector + bind_section + bind_panel_file + + bind = option.get('bind') + if not bind: + if bind_section: + bind = bind_section + else: + bind = 'settings' + elif bind[-1] == ":" and bind_section and ":" in bind_section: + selector, bind_file = bind_section.split(":") + if ">" in bind: + bind = bind + bind_file + else: + bind = selector + bind + bind_file + if bind == "settings" and option.get('type', 'string') == 'file': + bind = 'null' + + option["bind"] = _hydrate_app_template(bind, settings) + + def _dump_options_types_and_binds(self): + lines = [] + for _, _, option in self._iterate(): + lines.append('|'.join([option['id'], option.get('type', 'string'), option["bind"]])) + return '\n'.join(lines) + app_settings_cache: Dict[str, Dict[str, Any]] = {} app_settings_cache_timestamp: Dict[str, int] = {}