Showing with 23 additions and 6 deletions.
  1. +5 −0 data/actionsmap/yunohost.yml
  2. +1 −0 locales/en.json
  3. +17 −6 src/yunohost/settings.py
@@ -935,6 +935,10 @@ settings:
list:
action_help: list all entries of the settings
api: GET /settings
arguments:
-n:
full: --namespace
help: 'The namespace in which the settings is stored (eg: "ssl"))'

### settings_get()
get:
@@ -995,6 +999,7 @@ settings:
-s:
full: --fail-silently
help: Don't return 1 if the entry doesn't exists
action: store_true
-n:
full: --namespace
help: 'The namespace in which the settings is stored (eg: "ssl"))'
@@ -107,6 +107,7 @@
"firewall_rules_cmd_failed": "Some firewall rules commands have failed. For more information, see the log",
"format_datetime_short": "%m/%d/%Y %I:%M %p",
"global_settings_key_doesnt_exists": "The key '{settings_key:s}' doesn't exists in the global settings, you can see all the available keys by doing 'yunohost settings list",
"global_settings_namespace_is_empty": "The namespace '{namespace:s}' is empty or doesn't exists in the global settings",
"hook_exec_failed": "Script execution failed: {path:s}",
"hook_exec_not_terminated": "Script execution hasn’t terminated: {path:s}",
"hook_list_by_invalid": "Invalid property to list hook by",
@@ -3,7 +3,9 @@
import errno

from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger

logger = getActionLogger('yunohost.settings')

SETTINGS_PATH = "/etc/yunohost/settings.yaml"

@@ -16,10 +18,16 @@ def settings_get(key, default, namespace):


def settings_list(namespace=None):
settings = _get_settings()

if namespace is not None and not settings.get(namespace, {}):
logger.warning(m18n.n('global_settings_namespace_is_empty', namespace=namespace))
return {}

if namespace is not None:
return _get_settings().get(namespace, {})
else:
return _get_settings()
return settings.get(namespace, {})

return settings


def settings_exists(key, namespace):
@@ -39,12 +47,15 @@ def settings_set(key, value, namespace):
def settings_remove(key, namespace, fail_silently=False):
settings = _get_settings()

if key in settings.get(namespace, {}):
del settings.get(namespace, {})[key]
elif not fail_silently:
if key not in settings.get(namespace, {}):
raise MoulinetteError(errno.EINVAL, m18n.n(
'global_settings_key_doesnt_exists', settings_key=key))

del settings[namespace][key]

if not settings[namespace]:
del settings[namespace]

_save_settings(settings)