fix: remove json.get which is conflict with cli.root feature
This commit is contained in:
parent
f84bc007be
commit
852058e36f
4 changed files with 56 additions and 30 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2022-2025
|
Copyright (C) 2022-2026
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License as published by the
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
|
@ -38,6 +38,7 @@ class RougailOutputJson:
|
||||||
rougailconfig: "RougailConfig" = None,
|
rougailconfig: "RougailConfig" = None,
|
||||||
user_data_errors: Optional[list] = None,
|
user_data_errors: Optional[list] = None,
|
||||||
user_data_warnings: Optional[list] = None,
|
user_data_warnings: Optional[list] = None,
|
||||||
|
true_config: "Config" = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
if rougailconfig is None:
|
if rougailconfig is None:
|
||||||
|
|
@ -51,6 +52,10 @@ class RougailOutputJson:
|
||||||
)
|
)
|
||||||
self.rougailconfig = rougailconfig
|
self.rougailconfig = rougailconfig
|
||||||
self.config = config
|
self.config = config
|
||||||
|
if true_config:
|
||||||
|
self.true_config = true_config
|
||||||
|
else:
|
||||||
|
self.true_config = config
|
||||||
try:
|
try:
|
||||||
groups.namespace
|
groups.namespace
|
||||||
self.support_namespace = True
|
self.support_namespace = True
|
||||||
|
|
@ -80,23 +85,18 @@ class RougailOutputJson:
|
||||||
|
|
||||||
def exporter(self) -> None:
|
def exporter(self) -> None:
|
||||||
self.is_mandatory = self.rougailconfig["json.mandatory"]
|
self.is_mandatory = self.rougailconfig["json.mandatory"]
|
||||||
self.get = self.rougailconfig["json.get"]
|
|
||||||
self.dico = {}
|
self.dico = {}
|
||||||
if self.is_mandatory:
|
if self.is_mandatory and self.config.isoptiondescription():
|
||||||
ori_properties = self.config.property.exportation()
|
ori_properties = self.true_config.property.exportation()
|
||||||
self.config.property.read_write()
|
self.true_config.property.read_write()
|
||||||
self.mandatory()
|
self.mandatory()
|
||||||
self.config.property.importation(ori_properties)
|
self.true_config.property.importation(ori_properties)
|
||||||
self.manage_warnings()
|
self.manage_warnings()
|
||||||
if self.get:
|
if not self.config.isoptiondescription():
|
||||||
config = self.config.option(self.get)
|
self.dico = self.config.value.get()
|
||||||
if not config.isoptiondescription():
|
return True
|
||||||
self.dico = config.value.get()
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
config = self.config
|
|
||||||
self.parse_family(
|
self.parse_family(
|
||||||
config,
|
self.config,
|
||||||
self.dico,
|
self.dico,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
@ -168,10 +168,7 @@ class RougailOutputJson:
|
||||||
self.parse_family(option, parent, subnamespace)
|
self.parse_family(option, parent, subnamespace)
|
||||||
child[option.name()] = parent
|
child[option.name()] = parent
|
||||||
else:
|
else:
|
||||||
self.parse_variable(option, child, namespace)
|
child[option.name()] = option.value.get()
|
||||||
|
|
||||||
def parse_variable(self, option, child, namespace):
|
|
||||||
child[option.name()] = option.value.get()
|
|
||||||
|
|
||||||
def parse_leadership(
|
def parse_leadership(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2024-2025
|
Copyright (C) 2024-2026
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License as published by the
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
|
@ -44,15 +44,6 @@ json:
|
||||||
jinja: |-
|
jinja: |-
|
||||||
{{{{ cli.read_write is not defined or not cli.read_write }}}}
|
{{{{ cli.read_write is not defined or not cli.read_write }}}}
|
||||||
description: {_('true if "cli.read_write" is false')}
|
description: {_('true if "cli.read_write" is false')}
|
||||||
|
|
||||||
get:
|
|
||||||
description: {_('get value for a variable or a family')}
|
|
||||||
help: |-
|
|
||||||
{_('By default, the entire configuration is exported as JSON. It is possible to retrieve variables values from a defined family or directly the value of a variable.')}
|
|
||||||
examples:
|
|
||||||
- family
|
|
||||||
- family.variable
|
|
||||||
mandatory: false
|
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"name": "json",
|
"name": "json",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Internationalisation utilities
|
"""Internationalisation utilities
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2024-2025
|
Copyright (C) 2024-2026
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License as published by the
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from pytest import fixture # , raises
|
from pytest import fixture # , raises
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from rougail import Rougail
|
from rougail import Rougail, RougailConfig
|
||||||
from rougail.output_json import RougailOutputJson as RougailOutput
|
from rougail.output_json import RougailOutputJson as RougailOutput
|
||||||
|
|
||||||
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
|
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
|
||||||
|
|
@ -111,3 +111,41 @@ def test_structural_files_json_namespace_mandatory(test_dir):
|
||||||
|
|
||||||
def test_structural_files_json_namespace_mandatory_read_only(test_dir):
|
def test_structural_files_json_namespace_mandatory_read_only(test_dir):
|
||||||
_test_structural_files(test_dir, False, EXT, read_write=False, mandatory=True)
|
_test_structural_files(test_dir, False, EXT, read_write=False, mandatory=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_subconfig_family():
|
||||||
|
rougailconfig = RougailConfig.copy()
|
||||||
|
rougailconfig['step.output'] = 'json'
|
||||||
|
rougailconfig['main_structural_directories'] = [str(Path(__file__).parent / 'subconfig')]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
config.property.read_only()
|
||||||
|
generated_output = RougailOutput(config.option('rougail.a_family'), rougailconfig=rougailconfig, true_config=config).run()[1]
|
||||||
|
output_file = Path(__file__).parent / 'subconfig-results' / "family.json"
|
||||||
|
if not output_file.is_file():
|
||||||
|
if not output_file.parent.is_dir():
|
||||||
|
output_file.parent.mkdir()
|
||||||
|
with output_file.open('w') as outfh:
|
||||||
|
outfh.write(generated_output)
|
||||||
|
with output_file.open() as outfh:
|
||||||
|
attented_output = outfh.read()
|
||||||
|
assert generated_output == attented_output, f'filename {output_file}'
|
||||||
|
|
||||||
|
|
||||||
|
def test_subconfig_variable():
|
||||||
|
rougailconfig = RougailConfig.copy()
|
||||||
|
rougailconfig['step.output'] = 'json'
|
||||||
|
rougailconfig['main_structural_directories'] = [str(Path(__file__).parent / 'subconfig')]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
config.property.read_only()
|
||||||
|
generated_output = RougailOutput(config.option('rougail.a_family.a_sub_family.a_variable'), rougailconfig=rougailconfig, true_config=config).run()[1]
|
||||||
|
output_file = Path(__file__).parent / 'subconfig-results' / "variable.json"
|
||||||
|
if not output_file.is_file():
|
||||||
|
if not output_file.parent.is_dir():
|
||||||
|
output_file.parent.mkdir()
|
||||||
|
with output_file.open('w') as outfh:
|
||||||
|
outfh.write(generated_output)
|
||||||
|
with output_file.open() as outfh:
|
||||||
|
attented_output = outfh.read()
|
||||||
|
assert generated_output == attented_output, f'filename {output_file}'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue