From fde05c0ac2af8c2009be9952f7819604f9d56b6a Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Fri, 25 Aug 2023 20:53:30 +0200 Subject: [PATCH 1/4] [enh] bind heritage in config panel --- helpers/config | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/helpers/config b/helpers/config index 77f118c5f..6c6285cf6 100644 --- a/helpers/config +++ b/helpers/config @@ -108,11 +108,11 @@ _ynh_app_config_apply_one() { else local bind_after="" local bind_key_="$(echo "$bind" | cut -d: -f1)" - bind_key_=${bind_key_:-$short_setting} if [[ "$bind_key_" == *">"* ]]; then bind_after="$(echo "${bind_key_}" | cut -d'>' -f1)" bind_key_="$(echo "${bind_key_}" | cut -d'>' -f2)" fi + bind_key_=${bind_key_:-$short_setting} local bind_file="$(echo "$bind" | cut -d: -f2 | sed s@__INSTALL_DIR__@$install_dir@ | sed s@__FINALPATH__@$final_path@ | sed s/__APP__/$app/)" ynh_backup_if_checksum_is_different --file="$bind_file" @@ -139,15 +139,31 @@ loaded_toml = toml.loads(file_content, _dict=OrderedDict) for panel_name, panel in loaded_toml.items(): if not isinstance(panel, dict): continue + bind_panel = panel.get('bind') for section_name, section in panel.items(): if not isinstance(section, dict): continue + bind_section = section.get('bind', bind_panel) 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' if param.get('type', 'string') != 'file' else 'null' + 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 print(';'.join([ name, param.get('type', 'string'), - param.get('bind', 'settings' if param.get('type', 'string') != 'file' else 'null') + bind ])) EOL ) From 79e620ef428629a65b9717092cf4109d158fb168 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Fri, 25 Aug 2023 21:12:01 +0200 Subject: [PATCH 2/4] [fix] Conflict type file and settings bind mode --- helpers/config | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helpers/config b/helpers/config index 6c6285cf6..a44582acf 100644 --- a/helpers/config +++ b/helpers/config @@ -153,13 +153,16 @@ for panel_name, panel in loaded_toml.items(): if bind_section: bind = bind_section else: - bind = 'settings' if param.get('type', 'string') != 'file' else 'null' + 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'), From dcafac1913364e5da690c5c01af8fe62b68bee55 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Fri, 25 Aug 2023 22:36:33 +0200 Subject: [PATCH 3/4] [fix] Combine bind section regex with bind panel file --- helpers/config | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/helpers/config b/helpers/config index a44582acf..5a41822cc 100644 --- a/helpers/config +++ b/helpers/config @@ -142,7 +142,16 @@ for panel_name, panel in loaded_toml.items(): bind_panel = panel.get('bind') for section_name, section in panel.items(): if not isinstance(section, dict): continue - bind_section = section.get('bind', bind_panel) + bind_section = section.get('bind') + if not bind_section: + bind_section = bind_panel + elif bind_section[-1] == ":" and bind_panel and ":" in bind_panel: + regex, bind_panel_file = bind_panel.split(":") + if ">" 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 From 6f3b194944502460422d0f06c02a7fd225387f58 Mon Sep 17 00:00:00 2001 From: ljf Date: Sat, 2 Sep 2023 22:47:02 +0200 Subject: [PATCH 4/4] [fix] Avoid char conflict with bind properties --- helpers/config | 4 ++-- src/utils/configpanel.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/helpers/config b/helpers/config index 5a41822cc..fbf7febaa 100644 --- a/helpers/config +++ b/helpers/config @@ -172,7 +172,7 @@ for panel_name, panel in loaded_toml.items(): if bind == "settings" and param.get('type', 'string') == 'file': bind = 'null' - print(';'.join([ + print('|'.join([ name, param.get('type', 'string'), bind @@ -181,7 +181,7 @@ EOL ) for line in $lines; do # Split line into short_setting, type and bind - IFS=';' read short_setting type bind <<<"$line" + IFS='|' read short_setting type bind <<<"$line" binds[${short_setting}]="$bind" types[${short_setting}]="$type" file_hash[${short_setting}]="" diff --git a/src/utils/configpanel.py b/src/utils/configpanel.py index 12024855a..cc93f888f 100644 --- a/src/utils/configpanel.py +++ b/src/utils/configpanel.py @@ -345,14 +345,14 @@ class ConfigPanel: "defaults": {"version": 1.0}, }, "panels": { - "properties": ["name", "services", "actions", "help"], + "properties": ["name", "services", "actions", "help", "bind"], "defaults": { "services": [], "actions": {"apply": {"en": "Apply"}}, }, }, "sections": { - "properties": ["name", "services", "optional", "help", "visible"], + "properties": ["name", "services", "optional", "help", "visible", "bind"], "defaults": { "name": "", "services": [],