fix: correction for calculated variable with a variable in a dynamic family

This commit is contained in:
egarette@silique.fr 2024-01-28 18:58:20 +01:00
parent 4660a65303
commit 728e53e16e
264 changed files with 1036 additions and 46 deletions

View file

@ -47,6 +47,7 @@ import logging
from pathlib import Path
from typing import Optional, Union, get_type_hints, Any, Literal, List, Dict, Iterator, Tuple
from itertools import chain
from re import findall
from yaml import safe_load
from pydantic import ValidationError
@ -124,9 +125,28 @@ class Paths:
) -> Any:
suffix = None
dynamic_path = None
dynamic_variable_path = None
if not path in self._data:
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)
if (
subpaths[0]
@ -136,15 +156,16 @@ class Paths:
suffix = (
dynamic.rsplit(".", 1)[-1] + subpaths[0] + "." + subpaths[1]
)
dynamic_path = dynamic + "." + subpaths[1]
dynamic_path = dynamic
dynamic_variable_path = dynamic + "." + subpaths[1]
break
if suffix:
break
if suffix is None and not path in self._data:
return None, None
if suffix and dynamic_path:
path = dynamic_path
return self._data[path], suffix
return None, None, None
dynamic = None
if suffix and dynamic_variable_path:
path = dynamic_variable_path
dynamic = self._data[dynamic_path]
return self._data[path], suffix, dynamic
def __getitem__(
self,

View file

@ -85,7 +85,7 @@ class Calculation(BaseModel):
param = param_obj.model_dump()
if param.get("type") == "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 param.get("optional"):
raise Exception(f"cannot find {variable_path}")
@ -95,6 +95,7 @@ class Calculation(BaseModel):
param["variable"] = variable
if suffix:
param["suffix"] = suffix
param["dynamic"] = dynamic
if param.get("type") == "information":
if param["variable"]:
variable_path = self.get_realpath(param["variable"])
@ -147,7 +148,7 @@ class JinjaCalculation(Calculation):
default["params"] |= self.get_params(objectspace)
if 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,
objectspace,
variable.xmlfiles,
@ -161,6 +162,7 @@ class JinjaCalculation(Calculation):
}
if suffix:
default["params"][true_path]["suffix"] = suffix
default["params"][true_path]["dynamic"] = dynamic
return default
def to_function(
@ -230,7 +232,7 @@ class VariableCalculation(Calculation):
objectspace,
) -> dict:
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:
raise Exception(f"pffff {variable_path}")
if not isinstance(variable, objectspace.variable):
@ -242,6 +244,7 @@ class VariableCalculation(Calculation):
}
if suffix:
param["suffix"] = suffix
param["dynamic"] = dynamic
params = {None: [param]}
function = "calc_value"
help_function = None

View file

@ -393,6 +393,7 @@ class Common:
param["variable"],
param.get("propertyerror", True),
param.get("suffix"),
param.get("dynamic"),
)
if param["type"] == "any":
if isinstance(param["value"], str):
@ -407,6 +408,7 @@ class Common:
param,
propertyerror,
suffix: Optional[str],
dynamic,
) -> str:
"""build variable parameters"""
if param.path == self.elt.path:
@ -417,7 +419,7 @@ class Common:
params = [f"{option_name}"]
if suffix is not None:
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
)
params.extend([f"'{suffix}'", f"{family}"])

View file

@ -112,8 +112,8 @@ def get_jinja_variable_to_param(
variables = list(variables)
variables.sort()
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)
)
if variable and variable.path in objectspace.variables:
yield variable, suffix, variable_path
yield variable, suffix, variable_path, dynamic

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
["rougail.empty"]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
["rougail.general.adresse_ip_eth0", "rougail.general.adresse_netmask_eth0", "rougail.general.adresse_ip"]

View file

@ -0,0 +1 @@
["rougail.general.adresse_ip_eth0", "rougail.general.adresse_ip"]

View file

@ -0,0 +1 @@
["rougail.general.adresse_ip_eth0", "rougail.general.adresse_netmask_eth0"]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
["rougail.general.leader.leader"]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

Some files were not shown because too many files have changed in this diff Show more