Compare commits
No commits in common. "1d29366b7cd0808a1c893de0da893eb3af7fcc34" and "f84bc007beb416e99d59e5e8782b61514ad2375e" have entirely different histories.
1d29366b7c
...
f84bc007be
7 changed files with 32 additions and 64 deletions
|
|
@ -1,9 +1,3 @@
|
||||||
## 0.2.0a17 (2026-01-14)
|
|
||||||
|
|
||||||
### Fix
|
|
||||||
|
|
||||||
- remove json.get which is conflict with cli.root feature
|
|
||||||
|
|
||||||
## 0.2.0a16 (2025-12-30)
|
## 0.2.0a16 (2025-12-30)
|
||||||
|
|
||||||
### Feat
|
### Feat
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ requires = ["flit_core >=3.8.0,<4"]
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "rougail.output_json"
|
name = "rougail.output_json"
|
||||||
version = "0.2.0a17"
|
version = "0.2.0a16"
|
||||||
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
description = "Rougail output json"
|
description = "Rougail output json"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2022-2026
|
Copyright (C) 2022-2025
|
||||||
|
|
||||||
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,7 +38,6 @@ 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:
|
||||||
|
|
@ -52,10 +51,6 @@ 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
|
||||||
|
|
@ -85,18 +80,23 @@ 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 and self.config.isoptiondescription():
|
if self.is_mandatory:
|
||||||
ori_properties = self.true_config.property.exportation()
|
ori_properties = self.config.property.exportation()
|
||||||
self.true_config.property.read_write()
|
self.config.property.read_write()
|
||||||
self.mandatory()
|
self.mandatory()
|
||||||
self.true_config.property.importation(ori_properties)
|
self.config.property.importation(ori_properties)
|
||||||
self.manage_warnings()
|
self.manage_warnings()
|
||||||
if not self.config.isoptiondescription():
|
if self.get:
|
||||||
self.dico = self.config.value.get()
|
config = self.config.option(self.get)
|
||||||
return True
|
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,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
@ -168,7 +168,10 @@ class RougailOutputJson:
|
||||||
self.parse_family(option, parent, subnamespace)
|
self.parse_family(option, parent, subnamespace)
|
||||||
child[option.name()] = parent
|
child[option.name()] = parent
|
||||||
else:
|
else:
|
||||||
child[option.name()] = option.value.get()
|
self.parse_variable(option, child, namespace)
|
||||||
|
|
||||||
|
def parse_variable(self, option, child, namespace):
|
||||||
|
child[option.name()] = option.value.get()
|
||||||
|
|
||||||
def parse_leadership(
|
def parse_leadership(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__version__ = "0.2.0a17"
|
__version__ = "0.2.0a16"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Silique (https://www.silique.fr)
|
Silique (https://www.silique.fr)
|
||||||
Copyright (C) 2024-2026
|
Copyright (C) 2024-2025
|
||||||
|
|
||||||
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,6 +44,15 @@ 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-2026
|
Copyright (C) 2024-2025
|
||||||
|
|
||||||
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, RougailConfig
|
from rougail import Rougail
|
||||||
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,41 +111,3 @@ 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