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)
|
||||
Copyright (C) 2022-2025
|
||||
Copyright (C) 2022-2026
|
||||
|
||||
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
|
||||
|
|
@ -38,6 +38,7 @@ class RougailOutputJson:
|
|||
rougailconfig: "RougailConfig" = None,
|
||||
user_data_errors: Optional[list] = None,
|
||||
user_data_warnings: Optional[list] = None,
|
||||
true_config: "Config" = None,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
if rougailconfig is None:
|
||||
|
|
@ -51,6 +52,10 @@ class RougailOutputJson:
|
|||
)
|
||||
self.rougailconfig = rougailconfig
|
||||
self.config = config
|
||||
if true_config:
|
||||
self.true_config = true_config
|
||||
else:
|
||||
self.true_config = config
|
||||
try:
|
||||
groups.namespace
|
||||
self.support_namespace = True
|
||||
|
|
@ -80,23 +85,18 @@ class RougailOutputJson:
|
|||
|
||||
def exporter(self) -> None:
|
||||
self.is_mandatory = self.rougailconfig["json.mandatory"]
|
||||
self.get = self.rougailconfig["json.get"]
|
||||
self.dico = {}
|
||||
if self.is_mandatory:
|
||||
ori_properties = self.config.property.exportation()
|
||||
self.config.property.read_write()
|
||||
if self.is_mandatory and self.config.isoptiondescription():
|
||||
ori_properties = self.true_config.property.exportation()
|
||||
self.true_config.property.read_write()
|
||||
self.mandatory()
|
||||
self.config.property.importation(ori_properties)
|
||||
self.true_config.property.importation(ori_properties)
|
||||
self.manage_warnings()
|
||||
if self.get:
|
||||
config = self.config.option(self.get)
|
||||
if not config.isoptiondescription():
|
||||
self.dico = config.value.get()
|
||||
if not self.config.isoptiondescription():
|
||||
self.dico = self.config.value.get()
|
||||
return True
|
||||
else:
|
||||
config = self.config
|
||||
self.parse_family(
|
||||
config,
|
||||
self.config,
|
||||
self.dico,
|
||||
None,
|
||||
)
|
||||
|
|
@ -168,9 +168,6 @@ class RougailOutputJson:
|
|||
self.parse_family(option, parent, subnamespace)
|
||||
child[option.name()] = parent
|
||||
else:
|
||||
self.parse_variable(option, child, namespace)
|
||||
|
||||
def parse_variable(self, option, child, namespace):
|
||||
child[option.name()] = option.value.get()
|
||||
|
||||
def parse_leadership(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"""
|
||||
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
|
||||
under the terms of the GNU Lesser General Public License as published by the
|
||||
|
|
@ -44,15 +44,6 @@ json:
|
|||
jinja: |-
|
||||
{{{{ cli.read_write is not defined or not cli.read_write }}}}
|
||||
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 {
|
||||
"name": "json",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"""Internationalisation utilities
|
||||
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
|
||||
under the terms of the GNU Lesser General Public License as published by the
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from pytest import fixture # , raises
|
||||
from pathlib import Path
|
||||
from rougail import Rougail
|
||||
from rougail import Rougail, RougailConfig
|
||||
from rougail.output_json import RougailOutputJson as RougailOutput
|
||||
|
||||
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):
|
||||
_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