feat: add json.get to have sub variables

This commit is contained in:
egarette@silique.fr 2025-03-19 10:57:56 +01:00
parent 1ad5998930
commit 368cd17f33
2022 changed files with 2595 additions and 1976 deletions
src/rougail/output_json
tests/results
test
test_mandatory
test_namespace
test_namespace_mandatory
test_namespace_read_write
test_namespace_read_write_mandatory
test_namespace_read_write_mandatory_errors
test_read_write
test_read_write_mandatory
test_read_write_mandatory_errors

View file

@ -56,11 +56,16 @@ class RougailOutputJson:
self.warnings = [] self.warnings = []
self.read_write = self.rougailconfig["json.read_write"] self.read_write = self.rougailconfig["json.read_write"]
self.is_mandatory = self.rougailconfig["json.mandatory"] self.is_mandatory = self.rougailconfig["json.mandatory"]
self.get = self.rougailconfig["json.get"]
self.dico = {} self.dico = {}
def run(self) -> None: def run(self) -> None:
ret = self.exporter() ret = self.exporter()
return ret, dumps(self.dico, ensure_ascii=False, indent=2) + '\n' if isinstance(self.dico, str):
value = self.dico
else:
value = dumps(self.dico, ensure_ascii=False, indent=2)
return ret, value
def print(self) -> str: def print(self) -> str:
ret, data = self.run() ret, data = self.run()
@ -70,14 +75,21 @@ class RougailOutputJson:
def exporter(self) -> None: def exporter(self) -> None:
self.config.property.read_write() self.config.property.read_write()
self.mandatory() self.mandatory()
self.manage_warnings()
self.config.property.read_only() self.config.property.read_only()
if self.manage_errors(): if self.manage_errors():
return False return False
self.manage_warnings()
if self.read_write: if self.read_write:
self.config.property.read_write() self.config.property.read_write()
if self.get:
config = self.config.option(self.get)
if not config.isoptiondescription():
self.dico = config.value.get()
return True
else:
config = self.config
self.parse_family( self.parse_family(
self.config, config,
self.dico, self.dico,
) )
return True return True
@ -126,6 +138,7 @@ class RougailOutputJson:
if not self.errors: if not self.errors:
return False return False
self.dico = {"_errors": self.errors} self.dico = {"_errors": self.errors}
self.manage_warnings()
return True return True
def parse_family( def parse_family(

View file

@ -17,29 +17,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from pathlib import Path from pathlib import Path
from .i18n import _
def get_rougail_config( def get_rougail_config(
*, *,
backward_compatibility=True, backward_compatibility=True,
) -> dict: ) -> dict:
options = """ options = f"""
json: json:
description: Configuration rougail-json description: {_('configuration rougail-json')}
disabled: disabled:
type: jinja type: jinja
jinja: | jinja: |
{% if step.output != 'json' %} {{% if step.output is propertyerror or step.output != 'json' %}}
disabled disabled
{% endif %} {{% endif %}}
read_write: read_write:
description: Display variables available in read_write mode description: {_('display variables available in read_write mode')}
negative_description: Display variables available in read_only mode negative_description: {_('display variables available in read_only mode')}
default: false default: false
mandatory: mandatory:
description: Test mandatories variable before display in json description: {_('test mandatories variable before display in json')}
negative_description: Do not test mandatories variable before display in json negative_description: {_('do not test mandatories variable before display in json')}
default: true default: true
get:
description: {_('get value for a variable or a family')}
mandatory: false
""" """
return { return {
"name": "json", "name": "json",

View file

@ -0,0 +1,12 @@
{
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,12 @@
{
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,14 @@
{
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "string1",
"var2": "string1"
},
"dynval_2": {
"var1": "string1",
"var2": "string1"
}
}

View file

@ -0,0 +1,12 @@
{
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,12 @@
{
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,14 @@
{
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "string1",
"var2": "string1"
},
"dynval_2": {
"var1": "string1",
"var2": "string1"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "string1"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "string1"
}
}

View file

@ -0,0 +1,14 @@
{
"rougail": {
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,14 @@
{
"rougail": {
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,16 @@
{
"rougail": {
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "string1",
"var2": "string1"
},
"dynval_2": {
"var1": "string1",
"var2": "string1"
}
}
}

View file

@ -0,0 +1,11 @@
{
"rougail": {
"var1": [
"val1"
],
"dynval1": {
"var": "string1"
},
"var2": "string1"
}
}

View file

@ -0,0 +1,15 @@
{
"rougail": {
"var2": "string1",
"var1": [
"val1",
"val2"
],
"dynval1": {
"var": "string1"
},
"dynval2": {
"var": "string1"
}
}
}

View file

@ -0,0 +1,19 @@
{
"rougail": {
"var": [
"val1",
"val2"
],
"my_dyn_family_val1": {
"var": "string1"
},
"my_dyn_family_val2": {
"var": "string1"
},
"var2": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "string1"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "string1"
}
}

View file

@ -0,0 +1,14 @@
{
"rougail": {
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,14 @@
{
"rougail": {
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,16 @@
{
"rougail": {
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "string1",
"var2": "string1"
},
"dynval_2": {
"var1": "string1",
"var2": "string1"
}
}
}

View file

@ -0,0 +1,11 @@
{
"rougail": {
"var1": [
"val1"
],
"dynval1": {
"var": "string1"
},
"var2": "string1"
}
}

View file

@ -0,0 +1,15 @@
{
"rougail": {
"var2": "string1",
"var1": [
"val1",
"val2"
],
"dynval1": {
"var": "string1"
},
"dynval2": {
"var": "string1"
}
}
}

View file

@ -0,0 +1,19 @@
{
"rougail": {
"var": [
"val1",
"val2"
],
"my_dyn_family_val1": {
"var": "string1"
},
"my_dyn_family_val2": {
"var": "string1"
},
"var2": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "Rougail"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "Rougail"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"condition": []
}
}

View file

@ -0,0 +1,9 @@
{
"rougail": {
"condition": [
"val1",
"val2"
],
"variable": []
}
}

View file

@ -0,0 +1,16 @@
{
"rougail": {
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "val.1",
"var2": "val.1"
},
"dynval_2": {
"var1": "val.2",
"var2": "val.2"
}
}
}

View file

@ -0,0 +1,6 @@
{
"rougail": {
"var1": [],
"var2": null
}
}

View file

@ -0,0 +1,6 @@
{
"rougail": {
"var2": null,
"var1": []
}
}

View file

@ -0,0 +1,18 @@
{
"rougail": {
"var": [
"val1",
"val2"
],
"my_dyn_family_val1": {
"var": "val1"
},
"my_dyn_family_val2": {
"var": "val2"
},
"var2": [
"val1",
"val2"
]
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "string1"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "string1"
}
}

View file

@ -0,0 +1,14 @@
{
"rougail": {
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,14 @@
{
"rougail": {
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,16 @@
{
"rougail": {
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "string1",
"var2": "string1"
},
"dynval_2": {
"var1": "string1",
"var2": "string1"
}
}
}

View file

@ -0,0 +1,11 @@
{
"rougail": {
"var1": [
"val1"
],
"dynval1": {
"var": "string1"
},
"var2": "string1"
}
}

View file

@ -0,0 +1,15 @@
{
"rougail": {
"var2": "string1",
"var1": [
"val1",
"val2"
],
"dynval1": {
"var": "string1"
},
"dynval2": {
"var": "string1"
}
}
}

View file

@ -0,0 +1,19 @@
{
"rougail": {
"var": [
"val1",
"val2"
],
"my_dyn_family_val1": {
"var": "string1"
},
"my_dyn_family_val2": {
"var": "string1"
},
"var2": [
"string1",
"string2",
"string3"
]
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "Rougail"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"variable": "Rougail"
}
}

View file

@ -0,0 +1,6 @@
{
"_errors": [
"The following variables are mandatory but have no value:",
" - rougail.condition (a condition)"
]
}

View file

@ -0,0 +1,6 @@
{
"_errors": [
"The following variables are mandatory but have no value:",
" - rougail.variable (a variable)"
]
}

View file

@ -0,0 +1,16 @@
{
"rougail": {
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "val.1",
"var2": "val.1"
},
"dynval_2": {
"var1": "val.2",
"var2": "val.2"
}
}
}

View file

@ -0,0 +1,6 @@
{
"_errors": [
"The following variables are mandatory but have no value:",
" - rougail.var2 (A variable calculated)"
]
}

View file

@ -0,0 +1,6 @@
{
"_errors": [
"The following variables are mandatory but have no value:",
" - rougail.var2 (A variable calculated)"
]
}

View file

@ -0,0 +1,18 @@
{
"rougail": {
"var": [
"val1",
"val2"
],
"my_dyn_family_val1": {
"var": "val1"
},
"my_dyn_family_val2": {
"var": "val2"
},
"var2": [
"val1",
"val2"
]
}
}

View file

@ -0,0 +1,3 @@
{
"condition": []
}

View file

@ -0,0 +1,7 @@
{
"condition": [
"val1",
"val2"
],
"variable": []
}

View file

@ -0,0 +1,14 @@
{
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "val.1",
"var2": "val.1"
},
"dynval_2": {
"var1": "val.2",
"var2": "val.2"
}
}

View file

@ -0,0 +1,12 @@
{
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,12 @@
{
"condition": [
"string1",
"string2",
"string3"
],
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,14 @@
{
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "string1",
"var2": "string1"
},
"dynval_2": {
"var1": "string1",
"var2": "string1"
}
}

View file

@ -0,0 +1,6 @@
{
"_errors": [
"The following variables are mandatory but have no value:",
" - condition (a condition)"
]
}

View file

@ -0,0 +1,6 @@
{
"_errors": [
"The following variables are mandatory but have no value:",
" - variable (a variable)"
]
}

View file

@ -0,0 +1,14 @@
{
"var": [
"val.1",
"val.2"
],
"dynval_1": {
"var1": "val.1",
"var2": "val.1"
},
"dynval_2": {
"var1": "val.2",
"var2": "val.2"
}
}