mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Bind function for hotspot
This commit is contained in:
parent
bfa26ff469
commit
79126809eb
1 changed files with 160 additions and 131 deletions
|
@ -1,45 +1,22 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
_ynh_app_config_get() {
|
_ynh_app_config_get_one() {
|
||||||
# From settings
|
local short_setting="$1"
|
||||||
local lines
|
local type="$2"
|
||||||
lines=$(python3 << EOL
|
local bind="$3"
|
||||||
import toml
|
|
||||||
from collections import OrderedDict
|
|
||||||
with open("../config_panel.toml", "r") as f:
|
|
||||||
file_content = f.read()
|
|
||||||
loaded_toml = toml.loads(file_content, _dict=OrderedDict)
|
|
||||||
|
|
||||||
for panel_name, panel in loaded_toml.items():
|
|
||||||
if not isinstance(panel, dict): continue
|
|
||||||
for section_name, section in panel.items():
|
|
||||||
if not isinstance(section, dict): continue
|
|
||||||
for name, param in section.items():
|
|
||||||
if not isinstance(param, dict):
|
|
||||||
continue
|
|
||||||
print(';'.join([
|
|
||||||
name,
|
|
||||||
param.get('type', 'string'),
|
|
||||||
param.get('bind', 'settings' if param.get('type', 'string') != 'file' else 'null')
|
|
||||||
]))
|
|
||||||
EOL
|
|
||||||
)
|
|
||||||
for line in $lines
|
|
||||||
do
|
|
||||||
# Split line into short_setting, type and bind
|
|
||||||
IFS=';' read short_setting type bind <<< "$line"
|
|
||||||
local getter="get__${short_setting}"
|
local getter="get__${short_setting}"
|
||||||
binds[${short_setting}]="$bind"
|
|
||||||
types[${short_setting}]="$type"
|
|
||||||
file_hash[${short_setting}]=""
|
|
||||||
formats[${short_setting}]=""
|
|
||||||
# Get value from getter if exists
|
# Get value from getter if exists
|
||||||
if type -t $getter 2>/dev/null | grep -q '^function$' 2>/dev/null;
|
if type -t $getter 2>/dev/null | grep -q '^function$' 2>/dev/null;
|
||||||
then
|
then
|
||||||
old[$short_setting]="$($getter)"
|
old[$short_setting]="$($getter)"
|
||||||
formats[${short_setting}]="yaml"
|
formats[${short_setting}]="yaml"
|
||||||
|
|
||||||
|
elif [[ "$bind" == *"("* ]] && type -t "get__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null;
|
||||||
|
then
|
||||||
|
old[$short_setting]="$("get__${bind%%(*}" $short_setting $type $bind)"
|
||||||
|
formats[${short_setting}]="yaml"
|
||||||
|
|
||||||
elif [[ "$bind" == "null" ]]
|
elif [[ "$bind" == "null" ]]
|
||||||
then
|
then
|
||||||
old[$short_setting]="YNH_NULL"
|
old[$short_setting]="YNH_NULL"
|
||||||
|
@ -85,14 +62,9 @@ EOL
|
||||||
old[$short_setting]="$(ynh_read_var_in_file --file="${bind_file}" --key="${bind_key}" --after="${bind_after}")"
|
old[$short_setting]="$(ynh_read_var_in_file --file="${bind_file}" --key="${bind_key}" --after="${bind_after}")"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
_ynh_app_config_apply_one() {
|
||||||
_ynh_app_config_apply() {
|
local short_setting="$1"
|
||||||
for short_setting in "${!old[@]}"
|
|
||||||
do
|
|
||||||
local setter="set__${short_setting}"
|
local setter="set__${short_setting}"
|
||||||
local bind="${binds[$short_setting]}"
|
local bind="${binds[$short_setting]}"
|
||||||
local type="${types[$short_setting]}"
|
local type="${types[$short_setting]}"
|
||||||
|
@ -103,6 +75,10 @@ _ynh_app_config_apply() {
|
||||||
then
|
then
|
||||||
$setter
|
$setter
|
||||||
|
|
||||||
|
elif [[ "$bind" == *"("* ]] && type -t "set__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null;
|
||||||
|
then
|
||||||
|
"set__${bind%%(*}" $short_setting $type $bind
|
||||||
|
|
||||||
elif [[ "$bind" == "null" ]]
|
elif [[ "$bind" == "null" ]]
|
||||||
then
|
then
|
||||||
continue
|
continue
|
||||||
|
@ -172,6 +148,49 @@ _ynh_app_config_apply() {
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
_ynh_app_config_get() {
|
||||||
|
# From settings
|
||||||
|
local lines
|
||||||
|
lines=$(python3 << EOL
|
||||||
|
import toml
|
||||||
|
from collections import OrderedDict
|
||||||
|
with open("../config_panel.toml", "r") as f:
|
||||||
|
file_content = f.read()
|
||||||
|
loaded_toml = toml.loads(file_content, _dict=OrderedDict)
|
||||||
|
|
||||||
|
for panel_name, panel in loaded_toml.items():
|
||||||
|
if not isinstance(panel, dict): continue
|
||||||
|
for section_name, section in panel.items():
|
||||||
|
if not isinstance(section, dict): continue
|
||||||
|
for name, param in section.items():
|
||||||
|
if not isinstance(param, dict):
|
||||||
|
continue
|
||||||
|
print(';'.join([
|
||||||
|
name,
|
||||||
|
param.get('type', 'string'),
|
||||||
|
param.get('bind', 'settings' if param.get('type', 'string') != 'file' else 'null')
|
||||||
|
]))
|
||||||
|
EOL
|
||||||
|
)
|
||||||
|
for line in $lines
|
||||||
|
do
|
||||||
|
# Split line into short_setting, type and bind
|
||||||
|
IFS=';' read short_setting type bind <<< "$line"
|
||||||
|
binds[${short_setting}]="$bind"
|
||||||
|
types[${short_setting}]="$type"
|
||||||
|
file_hash[${short_setting}]=""
|
||||||
|
formats[${short_setting}]=""
|
||||||
|
ynh_app_config_get_one $short_setting $type $bind
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_ynh_app_config_apply() {
|
||||||
|
for short_setting in "${!old[@]}"
|
||||||
|
do
|
||||||
|
ynh_app_config_apply_one $short_setting
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +272,9 @@ _ynh_app_config_validate() {
|
||||||
if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null;
|
if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null;
|
||||||
then
|
then
|
||||||
result="$(validate__$short_setting)"
|
result="$(validate__$short_setting)"
|
||||||
|
elif [[ "$bind" == *"("* ]] && type -t "validate__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null;
|
||||||
|
then
|
||||||
|
"validate__${bind%%(*}" $short_setting
|
||||||
fi
|
fi
|
||||||
if [ -n "$result" ]
|
if [ -n "$result" ]
|
||||||
then
|
then
|
||||||
|
@ -283,6 +305,10 @@ _ynh_app_config_validate() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ynh_app_config_get_one() {
|
||||||
|
_ynh_app_config_get_one $1 $2 $3
|
||||||
|
}
|
||||||
|
|
||||||
ynh_app_config_get() {
|
ynh_app_config_get() {
|
||||||
_ynh_app_config_get
|
_ynh_app_config_get
|
||||||
}
|
}
|
||||||
|
@ -295,6 +321,9 @@ ynh_app_config_validate() {
|
||||||
_ynh_app_config_validate
|
_ynh_app_config_validate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ynh_app_config_apply_one() {
|
||||||
|
_ynh_app_config_apply_one $1
|
||||||
|
}
|
||||||
ynh_app_config_apply() {
|
ynh_app_config_apply() {
|
||||||
_ynh_app_config_apply
|
_ynh_app_config_apply
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue