fix: correction for calculated variable with a variable in a dynamic family
This commit is contained in:
parent
4660a65303
commit
728e53e16e
264 changed files with 1036 additions and 46 deletions
|
@ -47,6 +47,7 @@ import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union, get_type_hints, Any, Literal, List, Dict, Iterator, Tuple
|
from typing import Optional, Union, get_type_hints, Any, Literal, List, Dict, Iterator, Tuple
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
from re import findall
|
||||||
|
|
||||||
from yaml import safe_load
|
from yaml import safe_load
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
|
@ -124,9 +125,28 @@ class Paths:
|
||||||
) -> Any:
|
) -> Any:
|
||||||
suffix = None
|
suffix = None
|
||||||
dynamic_path = None
|
dynamic_path = None
|
||||||
|
dynamic_variable_path = None
|
||||||
if not path in self._data:
|
if not path in self._data:
|
||||||
for dynamic in self._dynamics:
|
for dynamic in self._dynamics:
|
||||||
if path.startswith(dynamic):
|
if "{{ suffix }}" in dynamic:
|
||||||
|
regexp = "^" + dynamic.replace('{{ suffix }}', '(.*)') + '.'
|
||||||
|
finded = findall(regexp, path)
|
||||||
|
if len(finded) != 1:
|
||||||
|
continue
|
||||||
|
splitted_dynamic = dynamic.split('.')
|
||||||
|
splitted_path = path.split('.')
|
||||||
|
for idx, s in enumerate(splitted_dynamic):
|
||||||
|
if '{{ suffix }}' in s:
|
||||||
|
break
|
||||||
|
|
||||||
|
suffix_path = '.'.join(splitted_path[idx + 1:])
|
||||||
|
if suffix_path:
|
||||||
|
suffix_path = "." + suffix_path
|
||||||
|
suffix = splitted_path[idx] + suffix_path
|
||||||
|
dynamic_path = dynamic
|
||||||
|
dynamic_variable_path = dynamic + suffix_path
|
||||||
|
break
|
||||||
|
elif path.startswith(dynamic):
|
||||||
subpaths = path[len(dynamic) :].split(".", 1)
|
subpaths = path[len(dynamic) :].split(".", 1)
|
||||||
if (
|
if (
|
||||||
subpaths[0]
|
subpaths[0]
|
||||||
|
@ -136,15 +156,16 @@ class Paths:
|
||||||
suffix = (
|
suffix = (
|
||||||
dynamic.rsplit(".", 1)[-1] + subpaths[0] + "." + subpaths[1]
|
dynamic.rsplit(".", 1)[-1] + subpaths[0] + "." + subpaths[1]
|
||||||
)
|
)
|
||||||
dynamic_path = dynamic + "." + subpaths[1]
|
dynamic_path = dynamic
|
||||||
break
|
dynamic_variable_path = dynamic + "." + subpaths[1]
|
||||||
if suffix:
|
|
||||||
break
|
break
|
||||||
if suffix is None and not path in self._data:
|
if suffix is None and not path in self._data:
|
||||||
return None, None
|
return None, None, None
|
||||||
if suffix and dynamic_path:
|
dynamic = None
|
||||||
path = dynamic_path
|
if suffix and dynamic_variable_path:
|
||||||
return self._data[path], suffix
|
path = dynamic_variable_path
|
||||||
|
dynamic = self._data[dynamic_path]
|
||||||
|
return self._data[path], suffix, dynamic
|
||||||
|
|
||||||
def __getitem__(
|
def __getitem__(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Calculation(BaseModel):
|
||||||
param = param_obj.model_dump()
|
param = param_obj.model_dump()
|
||||||
if param.get("type") == "variable":
|
if param.get("type") == "variable":
|
||||||
variable_path = self.get_realpath(param["variable"])
|
variable_path = self.get_realpath(param["variable"])
|
||||||
variable, suffix = objectspace.paths.get_with_dynamic(variable_path)
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(variable_path)
|
||||||
if not variable:
|
if not variable:
|
||||||
if not param.get("optional"):
|
if not param.get("optional"):
|
||||||
raise Exception(f"cannot find {variable_path}")
|
raise Exception(f"cannot find {variable_path}")
|
||||||
|
@ -95,6 +95,7 @@ class Calculation(BaseModel):
|
||||||
param["variable"] = variable
|
param["variable"] = variable
|
||||||
if suffix:
|
if suffix:
|
||||||
param["suffix"] = suffix
|
param["suffix"] = suffix
|
||||||
|
param["dynamic"] = dynamic
|
||||||
if param.get("type") == "information":
|
if param.get("type") == "information":
|
||||||
if param["variable"]:
|
if param["variable"]:
|
||||||
variable_path = self.get_realpath(param["variable"])
|
variable_path = self.get_realpath(param["variable"])
|
||||||
|
@ -147,7 +148,7 @@ class JinjaCalculation(Calculation):
|
||||||
default["params"] |= self.get_params(objectspace)
|
default["params"] |= self.get_params(objectspace)
|
||||||
if params:
|
if params:
|
||||||
default["params"] |= params
|
default["params"] |= params
|
||||||
for sub_variable, suffix, true_path in get_jinja_variable_to_param(
|
for sub_variable, suffix, true_path, dynamic in get_jinja_variable_to_param(
|
||||||
self.jinja,
|
self.jinja,
|
||||||
objectspace,
|
objectspace,
|
||||||
variable.xmlfiles,
|
variable.xmlfiles,
|
||||||
|
@ -161,6 +162,7 @@ class JinjaCalculation(Calculation):
|
||||||
}
|
}
|
||||||
if suffix:
|
if suffix:
|
||||||
default["params"][true_path]["suffix"] = suffix
|
default["params"][true_path]["suffix"] = suffix
|
||||||
|
default["params"][true_path]["dynamic"] = dynamic
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def to_function(
|
def to_function(
|
||||||
|
@ -230,7 +232,7 @@ class VariableCalculation(Calculation):
|
||||||
objectspace,
|
objectspace,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
variable_path = self.get_realpath(self.variable)
|
variable_path = self.get_realpath(self.variable)
|
||||||
variable, suffix = objectspace.paths.get_with_dynamic(variable_path)
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(variable_path)
|
||||||
if not variable:
|
if not variable:
|
||||||
raise Exception(f"pffff {variable_path}")
|
raise Exception(f"pffff {variable_path}")
|
||||||
if not isinstance(variable, objectspace.variable):
|
if not isinstance(variable, objectspace.variable):
|
||||||
|
@ -242,6 +244,7 @@ class VariableCalculation(Calculation):
|
||||||
}
|
}
|
||||||
if suffix:
|
if suffix:
|
||||||
param["suffix"] = suffix
|
param["suffix"] = suffix
|
||||||
|
param["dynamic"] = dynamic
|
||||||
params = {None: [param]}
|
params = {None: [param]}
|
||||||
function = "calc_value"
|
function = "calc_value"
|
||||||
help_function = None
|
help_function = None
|
||||||
|
|
|
@ -393,6 +393,7 @@ class Common:
|
||||||
param["variable"],
|
param["variable"],
|
||||||
param.get("propertyerror", True),
|
param.get("propertyerror", True),
|
||||||
param.get("suffix"),
|
param.get("suffix"),
|
||||||
|
param.get("dynamic"),
|
||||||
)
|
)
|
||||||
if param["type"] == "any":
|
if param["type"] == "any":
|
||||||
if isinstance(param["value"], str):
|
if isinstance(param["value"], str):
|
||||||
|
@ -407,6 +408,7 @@ class Common:
|
||||||
param,
|
param,
|
||||||
propertyerror,
|
propertyerror,
|
||||||
suffix: Optional[str],
|
suffix: Optional[str],
|
||||||
|
dynamic,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""build variable parameters"""
|
"""build variable parameters"""
|
||||||
if param.path == self.elt.path:
|
if param.path == self.elt.path:
|
||||||
|
@ -417,7 +419,7 @@ class Common:
|
||||||
params = [f"{option_name}"]
|
params = [f"{option_name}"]
|
||||||
if suffix is not None:
|
if suffix is not None:
|
||||||
param_type = "ParamDynOption"
|
param_type = "ParamDynOption"
|
||||||
family = self.tiramisu.reflector_objects[param.path.rsplit(".", 1)[0]].get(
|
family = self.tiramisu.reflector_objects[dynamic.path].get(
|
||||||
self.calls, self.elt.path
|
self.calls, self.elt.path
|
||||||
)
|
)
|
||||||
params.extend([f"'{suffix}'", f"{family}"])
|
params.extend([f"'{suffix}'", f"{family}"])
|
||||||
|
|
|
@ -112,8 +112,8 @@ def get_jinja_variable_to_param(
|
||||||
variables = list(variables)
|
variables = list(variables)
|
||||||
variables.sort()
|
variables.sort()
|
||||||
for variable_path in variables:
|
for variable_path in variables:
|
||||||
variable, suffix = objectspace.paths.get_with_dynamic(
|
variable, suffix, dynamic = objectspace.paths.get_with_dynamic(
|
||||||
get_realpath(variable_path, path_prefix)
|
get_realpath(variable_path, path_prefix)
|
||||||
)
|
)
|
||||||
if variable and variable.path in objectspace.variables:
|
if variable and variable.path in objectspace.variables:
|
||||||
yield variable, suffix, variable_path
|
yield variable, suffix, variable_path, dynamic
|
||||||
|
|
1
tests/dictionaries/00empty/makedict/mandatory.json
Normal file
1
tests/dictionaries/00empty/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.empty"]
|
1
tests/dictionaries/00load_notype/makedict/mandatory.json
Normal file
1
tests/dictionaries/00load_notype/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/00load_save/makedict/mandatory.json
Normal file
1
tests/dictionaries/00load_save/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/01base_float/makedict/mandatory.json
Normal file
1
tests/dictionaries/01base_float/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/01base_multi/makedict/mandatory.json
Normal file
1
tests/dictionaries/01base_multi/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/01test/makedict/mandatory.json
Normal file
1
tests/dictionaries/01test/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/01test_multi/makedict/mandatory.json
Normal file
1
tests/dictionaries/01test_multi/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/10check_base/makedict/mandatory.json
Normal file
1
tests/dictionaries/10check_base/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.adresse_ip_eth0", "rougail.general.adresse_netmask_eth0", "rougail.general.adresse_ip"]
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.adresse_ip_eth0", "rougail.general.adresse_ip"]
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.adresse_ip_eth0", "rougail.general.adresse_netmask_eth0"]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/10fill/makedict/mandatory.json
Normal file
1
tests/dictionaries/10fill/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
1
tests/dictionaries/10fill_quote/makedict/mandatory.json
Normal file
1
tests/dictionaries/10fill_quote/makedict/mandatory.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.general.leader.leader"]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
|
@ -0,0 +1 @@
|
||||||
|
[]
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue