1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

ynh_setting_get: epic regex is unreadable and breaks syntax highlighting, let's copypasta the official helper...

This commit is contained in:
Alexandre Aubin 2021-11-15 22:07:24 +01:00
parent 3ad8d0fa69
commit 38f61c775b

View file

@ -253,11 +253,19 @@ stop_hostapd() {
## Tools
ynh_setting_get() {
app=${1}
setting=${2}
grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
# '"
APP="$1" KEY="$2" python3 - <<EOF
import os, yaml, sys
app = os.environ['APP']
key = os.environ['KEY']
setting_file = "/etc/yunohost/apps/%s/settings.yml" % app
assert os.path.exists(setting_file), "Setting file %s does not exists ?" % setting_file
with open(setting_file) as f:
settings = yaml.safe_load(f)
if key in settings:
print(settings[key])
EOF
}
ynh_setting_set() {
@ -267,10 +275,10 @@ ynh_setting_set() {
# performance reasons (it takes a few second to run every yunohost commands)
# and to remove the need for the infamous '--need-lock' option/issue.
app="$1" key="$2" value="${3:-}" python3 - <<EOF
APP="$1" KEY="$2" VALUE="${3:-}" python3 - <<EOF
import os, yaml, sys
app = os.environ['app']
key, value = os.environ['key'], os.environ.get('value', None)
app = os.environ['APP']
key, value = os.environ['KEY'], os.environ.get('VALUE', None)
setting_file = "/etc/yunohost/apps/%s/settings.yml" % app
assert os.path.exists(setting_file), "Setting file %s does not exists ?" % setting_file
with open(setting_file) as f: