mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Multiple fixes in config panel
This commit is contained in:
parent
4c46f41036
commit
4547a6ec07
2 changed files with 55 additions and 34 deletions
|
@ -189,12 +189,18 @@ _ynh_panel_show() {
|
|||
|
||||
_ynh_panel_validate() {
|
||||
# Change detection
|
||||
ynh_script_progression --message="Checking what changed in the new configuration..." --weight=1
|
||||
local is_error=true
|
||||
#for changed_status in "${!changed[@]}"
|
||||
for short_setting in "${!old[@]}"
|
||||
do
|
||||
changed[$short_setting]=false
|
||||
[ -z ${!short_setting+x} ] && continue
|
||||
if [ -z ${!short_setting+x} ]; then
|
||||
# Assign the var with the old value in order to allows multiple
|
||||
# args validation
|
||||
declare "$short_setting"="${old[$short_setting]}"
|
||||
continue
|
||||
fi
|
||||
if [ ! -z "${file_hash[${short_setting}]}" ] ; then
|
||||
file_hash[old__$short_setting]=""
|
||||
file_hash[new__$short_setting]=""
|
||||
|
@ -217,10 +223,13 @@ _ynh_panel_validate() {
|
|||
fi
|
||||
fi
|
||||
done
|
||||
if [[ "$is_error" == "true" ]]
|
||||
then
|
||||
ynh_die "Nothing has changed"
|
||||
fi
|
||||
|
||||
# Run validation if something is changed
|
||||
if [[ "$is_error" == "false" ]]
|
||||
then
|
||||
ynh_script_progression --message="Validating the new configuration..." --weight=1
|
||||
|
||||
for short_setting in "${!old[@]}"
|
||||
do
|
||||
|
@ -231,16 +240,15 @@ _ynh_panel_validate() {
|
|||
fi
|
||||
if [ -n "$result" ]
|
||||
then
|
||||
local key="YNH_ERROR_${$short_setting}"
|
||||
local key="YNH_ERROR_${short_setting}"
|
||||
ynh_return "$key: $result"
|
||||
is_error=true
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ "$is_error" == "true" ]]
|
||||
then
|
||||
ynh_die ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
@ -266,11 +274,22 @@ ynh_panel_run() {
|
|||
declare -Ag changed=()
|
||||
declare -Ag file_hash=()
|
||||
declare -Ag sources=()
|
||||
|
||||
ynh_panel_get
|
||||
case $1 in
|
||||
show) ynh_panel_get && ynh_panel_show;;
|
||||
apply) ynh_panel_get && ynh_panel_validate && ynh_panel_apply;;
|
||||
show)
|
||||
ynh_panel_get
|
||||
ynh_panel_show
|
||||
;;
|
||||
apply)
|
||||
max_progression=4
|
||||
ynh_script_progression --message="Reading config panel description and current configuration..." --weight=1
|
||||
ynh_panel_get
|
||||
|
||||
ynh_panel_validate
|
||||
|
||||
ynh_script_progression --message="Applying the new configuration..." --weight=1
|
||||
ynh_panel_apply
|
||||
ynh_script_progression --message="Configuration of $app completed" --last
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
|
@ -1769,7 +1769,7 @@ def app_config_show(operation_logger, app, panel='', full=False):
|
|||
return None
|
||||
|
||||
# Call config script to extract current values
|
||||
parsed_values = _call_config_script(app, 'show')
|
||||
parsed_values = _call_config_script(operation_logger, app, 'show')
|
||||
|
||||
# # Check and transform values if needed
|
||||
# options = [option for _, _, option in _get_options_iterator(config_panel)]
|
||||
|
@ -1820,7 +1820,7 @@ def app_config_get(operation_logger, app, key):
|
|||
raise YunohostError("app_config_no_panel")
|
||||
|
||||
# Call config script to extract current values
|
||||
parsed_values = _call_config_script(app, 'show')
|
||||
parsed_values = _call_config_script(operation_logger, app, 'show')
|
||||
|
||||
logger.debug("Searching value")
|
||||
short_key = key.split('.')[-1]
|
||||
|
@ -1891,7 +1891,7 @@ def app_config_set(operation_logger, app, key=None, value=None, args=None):
|
|||
env = {key: value[0] for key, value in args_dict.items()}
|
||||
|
||||
try:
|
||||
errors = _call_config_script(app, 'apply', env=env)
|
||||
errors = _call_config_script(operation_logger, app, 'apply', env=env)
|
||||
# Here again, calling hook_exec could fail miserably, or get
|
||||
# manually interrupted (by mistake or because script was stuck)
|
||||
except (KeyboardInterrupt, EOFError, Exception):
|
||||
|
@ -1917,7 +1917,7 @@ def _get_options_iterator(config_panel):
|
|||
yield (panel, section, option)
|
||||
|
||||
|
||||
def _call_config_script(app, action, env={}):
|
||||
def _call_config_script(operation_logger, app, action, env={}):
|
||||
from yunohost.hook import hook_exec
|
||||
|
||||
# Add default config script if needed
|
||||
|
@ -1933,7 +1933,7 @@ ynh_panel_run $1
|
|||
write_to_file(config_script, default_script)
|
||||
|
||||
# Call config script to extract current values
|
||||
logger.debug("Calling 'show' action from config script")
|
||||
logger.debug(f"Calling '{action}' action from config script")
|
||||
app_id, app_instance_nb = _parse_app_instance_name(app)
|
||||
env.update({
|
||||
"app_id": app_id,
|
||||
|
@ -1941,9 +1941,11 @@ ynh_panel_run $1
|
|||
"app_instance_nb": str(app_instance_nb),
|
||||
})
|
||||
|
||||
_, parsed_values = hook_exec(
|
||||
ret, parsed_values = hook_exec(
|
||||
config_script, args=[action], env=env
|
||||
)
|
||||
if ret != 0:
|
||||
operation_logger.error(parsed_values)
|
||||
return parsed_values
|
||||
|
||||
|
||||
|
@ -3047,7 +3049,7 @@ class FileArgumentParser(YunoHostArgumentFormatParser):
|
|||
question.value = {
|
||||
'content': user_answers[question.name],
|
||||
'filename': user_answers.get(f"{question.name}[name]", question.name),
|
||||
} if user_answers[question.name] else None
|
||||
} if user_answers.get(question.name) else None
|
||||
return question
|
||||
|
||||
def _post_parse_value(self, question):
|
||||
|
|
Loading…
Add table
Reference in a new issue