mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add warning if bad keys in toml format
This commit is contained in:
parent
3b0bf74274
commit
da44224794
1 changed files with 37 additions and 25 deletions
|
@ -166,7 +166,7 @@ class ConfigPanel:
|
||||||
def _get_config_panel(self):
|
def _get_config_panel(self):
|
||||||
|
|
||||||
# Split filter_key
|
# Split filter_key
|
||||||
filter_key = self.filter_key.split(".")
|
filter_key = self.filter_key.split(".") if self.filter_key != "" else []
|
||||||
if len(filter_key) > 3:
|
if len(filter_key) > 3:
|
||||||
raise YunohostError("config_too_many_sub_keys", key=self.filter_key)
|
raise YunohostError("config_too_many_sub_keys", key=self.filter_key)
|
||||||
|
|
||||||
|
@ -181,21 +181,34 @@ class ConfigPanel:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Transform toml format into internal format
|
# Transform toml format into internal format
|
||||||
defaults = {
|
format_description = {
|
||||||
"toml": {"version": 1.0},
|
"toml": {
|
||||||
|
"properties": ["version", "i18n"],
|
||||||
|
"default": {"version": 1.0},
|
||||||
|
},
|
||||||
"panels": {
|
"panels": {
|
||||||
"name": "",
|
"properties": ["name", "services", "actions", "help"],
|
||||||
"services": [],
|
"default": {
|
||||||
"actions": {"apply": {"en": "Apply"}},
|
"name": "",
|
||||||
}, # help
|
"services": [],
|
||||||
|
"actions": {"apply": {"en": "Apply"}}
|
||||||
|
},
|
||||||
|
},
|
||||||
"sections": {
|
"sections": {
|
||||||
"name": "",
|
"properties": ["name", "services", "optional", "help", "visible"],
|
||||||
"services": [],
|
"default": {
|
||||||
"optional": True,
|
"name": "",
|
||||||
}, # visibleIf help
|
"services": [],
|
||||||
"options": {}
|
"optional": True,
|
||||||
# ask type source help helpLink example style icon placeholder visibleIf
|
}
|
||||||
# optional choices pattern limit min max step accept redact
|
},
|
||||||
|
"options": {
|
||||||
|
"properties": ["ask", "type", "source", "help", "example",
|
||||||
|
"style", "icon", "placeholder", "visible",
|
||||||
|
"optional", "choices", "yes", "no", "pattern",
|
||||||
|
"limit", "min", "max", "step", "accept", "redact"],
|
||||||
|
"default": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -214,19 +227,21 @@ class ConfigPanel:
|
||||||
This function detects all children nodes and put them in a list
|
This function detects all children nodes and put them in a list
|
||||||
"""
|
"""
|
||||||
# Prefill the node default keys if needed
|
# Prefill the node default keys if needed
|
||||||
default = defaults[node_type]
|
default = format_description[node_type]['default']
|
||||||
node = {key: toml_node.get(key, value) for key, value in default.items()}
|
node = {key: toml_node.get(key, value) for key, value in default.items()}
|
||||||
|
|
||||||
|
properties = format_description[node_type]['properties']
|
||||||
|
|
||||||
# Define the filter_key part to use and the children type
|
# Define the filter_key part to use and the children type
|
||||||
i = list(defaults).index(node_type)
|
i = list(format_description).index(node_type)
|
||||||
search_key = filter_key.get(i)
|
subnode_type = list(format_description)[i + 1] if node_type != "options" else None
|
||||||
subnode_type = list(defaults)[i + 1] if node_type != "options" else None
|
search_key = filter_key[i] if len(filter_key) > i else False
|
||||||
|
|
||||||
for key, value in toml_node.items():
|
for key, value in toml_node.items():
|
||||||
# Key/value are a child node
|
# Key/value are a child node
|
||||||
if (
|
if (
|
||||||
isinstance(value, OrderedDict)
|
isinstance(value, OrderedDict)
|
||||||
and key not in default
|
and key not in properties
|
||||||
and subnode_type
|
and subnode_type
|
||||||
):
|
):
|
||||||
# We exclude all nodes not referenced by the filter_key
|
# We exclude all nodes not referenced by the filter_key
|
||||||
|
@ -240,6 +255,8 @@ class ConfigPanel:
|
||||||
node.setdefault(subnode_type, []).append(subnode)
|
node.setdefault(subnode_type, []).append(subnode)
|
||||||
# Key/value are a property
|
# Key/value are a property
|
||||||
else:
|
else:
|
||||||
|
if key not in properties:
|
||||||
|
logger.warning(f"Unknown key '{key}' found in config toml")
|
||||||
# Todo search all i18n keys
|
# Todo search all i18n keys
|
||||||
node[key] = (
|
node[key] = (
|
||||||
value if key not in ["ask", "help", "name"] else {"en": value}
|
value if key not in ["ask", "help", "name"] else {"en": value}
|
||||||
|
@ -378,7 +395,6 @@ class Question(object):
|
||||||
self.pattern = question.get("pattern")
|
self.pattern = question.get("pattern")
|
||||||
self.ask = question.get("ask", {"en": self.name})
|
self.ask = question.get("ask", {"en": self.name})
|
||||||
self.help = question.get("help")
|
self.help = question.get("help")
|
||||||
self.helpLink = question.get("helpLink")
|
|
||||||
self.value = user_answers.get(self.name)
|
self.value = user_answers.get(self.name)
|
||||||
self.redact = question.get("redact", False)
|
self.redact = question.get("redact", False)
|
||||||
|
|
||||||
|
@ -471,15 +487,11 @@ class Question(object):
|
||||||
if self.choices:
|
if self.choices:
|
||||||
text_for_user_input_in_cli += " [{0}]".format(" | ".join(self.choices))
|
text_for_user_input_in_cli += " [{0}]".format(" | ".join(self.choices))
|
||||||
|
|
||||||
if self.help or self.helpLink:
|
if self.help:
|
||||||
text_for_user_input_in_cli += ":\033[m"
|
text_for_user_input_in_cli += ":\033[m"
|
||||||
if self.help:
|
if self.help:
|
||||||
text_for_user_input_in_cli += "\n - "
|
text_for_user_input_in_cli += "\n - "
|
||||||
text_for_user_input_in_cli += _value_for_locale(self.help)
|
text_for_user_input_in_cli += _value_for_locale(self.help)
|
||||||
if self.helpLink:
|
|
||||||
if not isinstance(self.helpLink, dict):
|
|
||||||
self.helpLink = {"href": self.helpLink}
|
|
||||||
text_for_user_input_in_cli += f"\n - See {self.helpLink['href']}"
|
|
||||||
return text_for_user_input_in_cli
|
return text_for_user_input_in_cli
|
||||||
|
|
||||||
def _post_parse_value(self):
|
def _post_parse_value(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue