feat: family or dynamic could needs type attribute
This commit is contained in:
parent
6f18fbb701
commit
f1b8ea81cb
4 changed files with 65 additions and 5 deletions
|
|
@ -77,6 +77,18 @@ RoundTripRepresenter.add_representer(str, represent_str)
|
||||||
# XXX
|
# XXX
|
||||||
|
|
||||||
|
|
||||||
|
class RougailConvertFormatter(RougailConvert):
|
||||||
|
def parse_root_file(
|
||||||
|
self,
|
||||||
|
filename: str,
|
||||||
|
path: str,
|
||||||
|
version: str,
|
||||||
|
objects: dict,
|
||||||
|
) -> None:
|
||||||
|
self.objects = objects
|
||||||
|
super().parse_root_file(filename, path, version, objects)
|
||||||
|
|
||||||
|
|
||||||
class RougailOutputFormatter:
|
class RougailOutputFormatter:
|
||||||
output_name = "formatter"
|
output_name = "formatter"
|
||||||
|
|
||||||
|
|
@ -161,7 +173,7 @@ class RougailOutputFormatter:
|
||||||
filename
|
filename
|
||||||
)
|
)
|
||||||
self.version_name, datas = RougailUpgrade(self.rougailconfig).run(filename)
|
self.version_name, datas = RougailUpgrade(self.rougailconfig).run(filename)
|
||||||
self.rougail = RougailConvert(self.rougailconfig)
|
self.rougail = RougailConvertFormatter(self.rougailconfig)
|
||||||
self.rougail.load_config()
|
self.rougail.load_config()
|
||||||
self.rougail.init()
|
self.rougail.init()
|
||||||
self.filename_str = str(filename)
|
self.filename_str = str(filename)
|
||||||
|
|
@ -239,10 +251,36 @@ class RougailOutputFormatter:
|
||||||
attr = f"_{attr}"
|
attr = f"_{attr}"
|
||||||
family[attr] = self.object_to_yaml(attr, type_, value, False, path)
|
family[attr] = self.object_to_yaml(attr, type_, value, False, path)
|
||||||
if type_ == "dynamic" or (children and type_ == "family"):
|
if type_ == "dynamic" or (children and type_ == "family"):
|
||||||
if "_type" in family:
|
tmp_family = family.copy()
|
||||||
del family["_type"]
|
if "_type" in tmp_family:
|
||||||
|
del tmp_family["_type"]
|
||||||
else:
|
else:
|
||||||
del family["type"]
|
del tmp_family["type"]
|
||||||
|
for child_path in self.rougail.parents[path]:
|
||||||
|
child = self.rougail.objects
|
||||||
|
if self.rougail.has_namespace:
|
||||||
|
split_path = child_path.split('.')[1:]
|
||||||
|
else:
|
||||||
|
split_path = child_path.split('.')
|
||||||
|
for cpath in split_path:
|
||||||
|
if cpath not in child and '{{ identifier }}' in cpath:
|
||||||
|
# support format 1.0
|
||||||
|
if cpath.replace('{{ identifier }}', '') in child:
|
||||||
|
cpath = cpath.replace('{{ identifier }}', '')
|
||||||
|
elif cpath.replace('{{ identifier }}', '{{ suffix }}') in child:
|
||||||
|
cpath = cpath.replace('{{ identifier }}', '{{ suffix }}')
|
||||||
|
child = child[cpath]
|
||||||
|
tmp_family[cpath] = child
|
||||||
|
family_type = self.rougail.is_family_or_variable("", tmp_family, False, "")
|
||||||
|
if family_type == "family":
|
||||||
|
family_type = self.rougail.get_family_or_variable_type(tmp_family)
|
||||||
|
if family_type is None:
|
||||||
|
family_type = 'family'
|
||||||
|
if family_type == type_:
|
||||||
|
if "_type" in family:
|
||||||
|
del family["_type"]
|
||||||
|
else:
|
||||||
|
del family["type"]
|
||||||
if not set(family):
|
if not set(family):
|
||||||
ret[name] = CommentedMap()
|
ret[name] = CommentedMap()
|
||||||
ret.yaml_value_comment_extend(
|
ret.yaml_value_comment_extend(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
my_family:
|
||||||
|
type: family
|
||||||
|
|
||||||
|
dynamic:
|
||||||
|
- val1
|
||||||
|
- val2
|
||||||
|
|
||||||
|
var: true # a variable
|
||||||
|
...
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
my_family:
|
||||||
|
type: family
|
||||||
|
|
||||||
|
default: true
|
||||||
|
...
|
||||||
|
|
@ -15,7 +15,7 @@ excludes = [
|
||||||
]
|
]
|
||||||
|
|
||||||
test_ok = get_structures_list(excludes)
|
test_ok = get_structures_list(excludes)
|
||||||
# test_ok = [Path('../rougail-tests/structures/40_2leadership_calculation_index')]
|
# test_ok = [Path('../rougail-tests/structures/60_6family_dynamic_sub_dynamic_1_0_2')]
|
||||||
|
|
||||||
|
|
||||||
def idfn(fixture_value):
|
def idfn(fixture_value):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue