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
00_0empty.json00_0version_underscore.json00_1empty_variable.json00_2default_calculated.json00_2default_calculated_multi.json00_2default_calculated_variable_transitive.json00_4load_subfolder.json00_5load_notype.json00_6boolean.json00_6boolean_no_mandatory.json00_6choice.json00_6choice_calculation.json00_6choice_variable.json00_6custom.json00_6domainname.json00_6domainname_params.json00_6float.json00_6number.json00_6port.json00_6regexp.json00_6secret.json00_6string.json00_7choice_quote.json00_7help_quote.json00_7value_doublequote.json00_7value_doublequote2.json00_7value_doublequote3.json00_7value_quote.json00_8calculation_information.json00_8test.json00_9choice_variable_multi.json00_9choice_variables.json00_9default_calculation.json00_9default_calculation_information.json00_9default_calculation_information_other_variable.json00_9default_calculation_multi_optional.json00_9default_calculation_multi_optional2.json00_9default_calculation_optional.json00_9default_calculation_optional_exists.json00_9default_calculation_param_optional.json00_9default_information_other_variable.json00_9default_information_other_variable2.json00_9default_integer.json01_6boolean_multi.json01_6custom_multi.json01_6float_multi.json01_6number_multi.json01_6string_empty.json01_6string_multi.json01_7value_multi_doublequote.json01_7value_multi_doublequote2.json01_7value_multi_quote.json01_8calculation_information_multi.json01_9choice_variable_multi.json04_0type_param.json04_1auto_save.json04_1auto_save_and_calculated.json04_1auto_save_and_calculated_hidden.json04_1auto_save_and_hidden.json04_1default_calculation_hidden.json04_1default_calculation_hidden_2.json04_5disabled_calculation_optional.json04_5disabled_calculation_variable.json04_5disabled_calculation_variable2.json04_5disabled_calculation_variable3.json04_5disabled_calculation_variable4.json04_5disabled_calculation_variable_multi.json04_5disabled_calculation_variable_multi2.json04_5disabled_calculation_variable_multi3.json04_5validators.json04_5validators_differ.json04_5validators_multi.json04_5validators_multi2.json05_0multi_not_uniq.json05_0multi_uniq.json12_1auto_save_expert.json16_0redefine_description.json16_2family_redefine_calculation.json16_2family_redefine_disabled.json16_5exists_nonexists.json16_5exists_redefine.json16_5redefine_calculation.json16_5redefine_choice.json16_5redefine_default.json16_5redefine_default_calculation.json16_5redefine_family.json16_5redefine_help.json16_5redefine_hidden.json16_5redefine_multi.json16_5redefine_remove_disable_calculation.json16_5test_redefine.json16_6choice_redefine.json16_6exists_family.json16_6exists_redefine_family.json16exists_exists.json17_5redefine_leadership.json20_0empty_family.json20_0family_append.json

View file

@ -56,11 +56,16 @@ class RougailOutputJson:
self.warnings = []
self.read_write = self.rougailconfig["json.read_write"]
self.is_mandatory = self.rougailconfig["json.mandatory"]
self.get = self.rougailconfig["json.get"]
self.dico = {}
def run(self) -> None:
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:
ret, data = self.run()
@ -70,14 +75,21 @@ class RougailOutputJson:
def exporter(self) -> None:
self.config.property.read_write()
self.mandatory()
self.manage_warnings()
self.config.property.read_only()
if self.manage_errors():
return False
self.manage_warnings()
if self.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.config,
config,
self.dico,
)
return True
@ -126,6 +138,7 @@ class RougailOutputJson:
if not self.errors:
return False
self.dico = {"_errors": self.errors}
self.manage_warnings()
return True
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 .i18n import _
def get_rougail_config(
*,
backward_compatibility=True,
) -> dict:
options = """
options = f"""
json:
description: Configuration rougail-json
description: {_('configuration rougail-json')}
disabled:
type: jinja
jinja: |
{% if step.output != 'json' %}
{{% if step.output is propertyerror or step.output != 'json' %}}
disabled
{% endif %}
{{% endif %}}
read_write:
description: Display variables available in read_write mode
negative_description: Display variables available in read_only mode
description: {_('display variables available in read_write mode')}
negative_description: {_('display variables available in read_only mode')}
default: false
mandatory:
description: Test mandatories variable before display in json
negative_description: Do not 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')}
default: true
get:
description: {_('get value for a variable or a family')}
mandatory: false
"""
return {
"name": "json",

View file

@ -1 +1 @@
{}
{}

View file

@ -1,3 +1,3 @@
{
"version": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"empty": "string1"
}
}

View file

@ -5,4 +5,4 @@
"string2",
"string3"
]
}
}

View file

@ -9,4 +9,4 @@
"string2",
"string3"
]
}
}

View file

@ -7,4 +7,4 @@
"domain1.lan",
"domain2.lan"
]
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"without_type": "string1"
}
}

View file

@ -5,4 +5,4 @@
"var4": true,
"var5": true,
"var6": true
}
}

View file

@ -1,3 +1,3 @@
{
"variable": true
}
}

View file

@ -5,4 +5,4 @@
"var4": null,
"var5": "a",
"var6": 1
}
}

View file

@ -1,3 +1,3 @@
{
"var": 0
}
}

View file

@ -5,4 +5,4 @@
"string3"
],
"var2": "string1"
}
}

View file

@ -1,4 +1,4 @@
{
"custom1": "string1",
"custom2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "domain1.lan"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "domain1.lan"
}
}

View file

@ -5,4 +5,4 @@
"var4": 1.1,
"var5": 1.1,
"var6": 1.1
}
}

View file

@ -5,4 +5,4 @@
"var4": 1,
"var5": 1,
"var6": 1
}
}

View file

@ -2,4 +2,4 @@
"variable1": "80",
"variable2": "80",
"variable3": "80"
}
}

View file

@ -1,3 +1,3 @@
{
"var": "#b1b1b1"
}
}

View file

@ -1,4 +1,4 @@
{
"secret1": "string1",
"secret2": "string1"
}
}

View file

@ -5,4 +5,4 @@
"var4": "string1",
"var5": "string1",
"var6": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"var": "quote'"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -8,4 +8,4 @@
"test1",
"test2"
]
}
}

View file

@ -7,4 +7,4 @@
"val1",
"val2"
]
}
}

View file

@ -2,4 +2,4 @@
"source_variable_1": "string1",
"source_variable_2": "string1",
"my_variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"var": "string1"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -5,4 +5,4 @@
"string2",
"string3"
]
}
}

View file

@ -5,4 +5,4 @@
"string2",
"string3"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -9,4 +9,4 @@
"string2",
"string3"
]
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"var": 0
}
}

View file

@ -23,4 +23,4 @@
"var8": [
true
]
}
}

View file

@ -9,4 +9,4 @@
"string2",
"string3"
]
}
}

View file

@ -39,4 +39,4 @@
2.2,
3.3
]
}
}

View file

@ -39,4 +39,4 @@
2,
3
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -39,4 +39,4 @@
"string2",
"string3"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -5,4 +5,4 @@
"string3"
],
"variable2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"int": 1
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "no"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "no"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "yes"
}
}

View file

@ -1,3 +1,3 @@
{
"var": "yes"
}
}

View file

@ -2,4 +2,4 @@
"var1": "string1",
"var2": "string1",
"var3": "string1"
}
}

View file

@ -2,4 +2,4 @@
"var1": "string1",
"var2": "string1",
"var3": "string1"
}
}

View file

@ -2,4 +2,4 @@
"condition": "string1",
"var1": null,
"var2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"condition": true
}
}

View file

@ -1,3 +1,3 @@
{
"condition": true
}
}

View file

@ -1,4 +1,4 @@
{
"condition": "string1",
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"condition": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"condition": true
}
}

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

@ -1,3 +1,3 @@
{
"int": 1
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "another_value",
"var2": "string1"
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -3,4 +3,4 @@
"val1",
"val2"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -1,3 +1,3 @@
{
"var": "no"
}
}

View file

@ -1,3 +1,3 @@
{
"var": "string1"
}
}

View file

@ -1,4 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"var1": "yes"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "a"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "string1"
}
}

View file

@ -2,4 +2,4 @@
"family": {
"variable": "string1"
}
}
}

View file

@ -2,4 +2,4 @@
"family": {
"variable": "string1"
}
}
}

View file

@ -1,3 +1,3 @@
{
"variable": "no"
}
}

View file

@ -4,4 +4,4 @@
"string2",
"string3"
]
}
}

View file

@ -1,4 +1,4 @@
{
"condition": "string1",
"variable": "string1"
}
}

View file

@ -2,4 +2,4 @@
"var1": "test1",
"var2": "test1",
"var3": "string1"
}
}

View file

@ -1,3 +1,3 @@
{
"var": "a"
}
}

View file

@ -1 +1 @@
{}
{}

View file

@ -5,4 +5,4 @@
"family2": {
"variable2": "string1"
}
}
}

View file

@ -1,3 +1,3 @@
{
"var": "string1"
}
}

View file

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

View file

@ -1 +1 @@
{}
{}

View file

@ -3,4 +3,4 @@
"var1": "string1",
"var2": "string1"
}
}
}

Some files were not shown because too many files have changed in this diff Show more