reorganise
This commit is contained in:
parent
0b8a6e399a
commit
cbd11a29c2
|
@ -25,9 +25,9 @@ class SpaceAnnotator: # pylint: disable=R0903
|
||||||
FillAnnotator(objectspace,
|
FillAnnotator(objectspace,
|
||||||
eosfunc_file,
|
eosfunc_file,
|
||||||
)
|
)
|
||||||
|
ValueAnnotator(objectspace)
|
||||||
FamilyAnnotator(objectspace)
|
FamilyAnnotator(objectspace)
|
||||||
PropertyAnnotator(objectspace)
|
PropertyAnnotator(objectspace)
|
||||||
ValueAnnotator(objectspace)
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ('SpaceAnnotator', 'CONVERT_OPTION', 'modes')
|
__all__ = ('SpaceAnnotator', 'CONVERT_OPTION', 'modes')
|
||||||
|
|
|
@ -196,7 +196,9 @@ class ConditionAnnotator:
|
||||||
variable = self.objectspace.paths.get_family(target.name.path,
|
variable = self.objectspace.paths.get_family(target.name.path,
|
||||||
target.namespace,
|
target.namespace,
|
||||||
)
|
)
|
||||||
|
if hasattr(variable, 'variable'):
|
||||||
return variable, list(variable.variable.values())
|
return variable, list(variable.variable.values())
|
||||||
|
return variable, []
|
||||||
|
|
||||||
def convert_condition_source(self):
|
def convert_condition_source(self):
|
||||||
"""remove condition for ChoiceOption that don't have param
|
"""remove condition for ChoiceOption that don't have param
|
||||||
|
|
|
@ -132,39 +132,13 @@ class FamilyAnnotator:
|
||||||
family_mode: str,
|
family_mode: str,
|
||||||
is_follower=False,
|
is_follower=False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""if the variable is mandatory and doesn't have any value
|
|
||||||
then the variable's mode is set to 'basic'
|
|
||||||
"""
|
|
||||||
# a boolean must have value, the default value is "True"
|
|
||||||
if not hasattr(variable, 'value') and variable.type == 'boolean':
|
|
||||||
new_value = self.objectspace.value(variable.xmlfiles)
|
|
||||||
new_value.name = True
|
|
||||||
new_value.type = 'boolean'
|
|
||||||
variable.value = [new_value]
|
|
||||||
# variable with default value is mandatory
|
|
||||||
if hasattr(variable, 'value') and variable.value:
|
|
||||||
has_value = True
|
|
||||||
for value in variable.value:
|
|
||||||
if value.type == 'calculation':
|
|
||||||
has_value = False
|
|
||||||
break
|
|
||||||
if has_value:
|
|
||||||
# if has value without any calculation
|
|
||||||
variable.mandatory = True
|
|
||||||
# mandatory variable without value is a basic variable
|
# mandatory variable without value is a basic variable
|
||||||
if variable.mandatory is True and (not hasattr(variable, 'value') or is_follower):
|
if variable.mandatory is True and not hasattr(variable, 'default'):
|
||||||
variable.mode = modes_level[0]
|
variable.mode = modes_level[0]
|
||||||
# none basic variable in high level family has to be in high level
|
# none basic variable in high level family has to be in high level
|
||||||
if modes[variable.mode] < modes[family_mode] and \
|
if modes[variable.mode] < modes[family_mode] and \
|
||||||
(not is_follower or variable.mode != modes_level[0]):
|
(not is_follower or variable.mode != modes_level[0]):
|
||||||
variable.mode = family_mode
|
variable.mode = family_mode
|
||||||
# hidden variable is also frozen
|
|
||||||
if variable.hidden is True:
|
|
||||||
variable.frozen = True
|
|
||||||
if not variable.auto_save and \
|
|
||||||
not variable.auto_freeze and \
|
|
||||||
'force_default_on_freeze' not in vars(variable):
|
|
||||||
variable.force_default_on_freeze = True
|
|
||||||
|
|
||||||
def change_family_mode(self):
|
def change_family_mode(self):
|
||||||
"""change mode of a family
|
"""change mode of a family
|
||||||
|
|
|
@ -26,9 +26,15 @@ class PropertyAnnotator:
|
||||||
) -> None:
|
) -> None:
|
||||||
"""convert properties
|
"""convert properties
|
||||||
"""
|
"""
|
||||||
|
# hidden variable is also frozen
|
||||||
|
if isinstance(variable, self.objectspace.variable) and variable.hidden is True:
|
||||||
|
variable.frozen = True
|
||||||
|
if not variable.auto_save and \
|
||||||
|
not variable.auto_freeze and \
|
||||||
|
'force_default_on_freeze' not in vars(variable):
|
||||||
|
variable.force_default_on_freeze = True
|
||||||
if not hasattr(variable, 'properties'):
|
if not hasattr(variable, 'properties'):
|
||||||
variable.properties = []
|
variable.properties = []
|
||||||
|
|
||||||
for prop in PROPERTIES:
|
for prop in PROPERTIES:
|
||||||
if hasattr(variable, prop):
|
if hasattr(variable, prop):
|
||||||
if getattr(variable, prop) is True:
|
if getattr(variable, prop) is True:
|
||||||
|
|
|
@ -17,6 +17,8 @@ class ValueAnnotator: # pylint: disable=R0903
|
||||||
"""
|
"""
|
||||||
for families in self.objectspace.space.variables.values():
|
for families in self.objectspace.space.variables.values():
|
||||||
for family in families.family.values():
|
for family in families.family.values():
|
||||||
|
if not hasattr(family, 'variable'):
|
||||||
|
continue
|
||||||
for variable in family.variable.values():
|
for variable in family.variable.values():
|
||||||
if isinstance(variable, self.objectspace.leadership):
|
if isinstance(variable, self.objectspace.leadership):
|
||||||
variable_type = 'leader'
|
variable_type = 'leader'
|
||||||
|
@ -28,10 +30,29 @@ class ValueAnnotator: # pylint: disable=R0903
|
||||||
else:
|
else:
|
||||||
self._convert_value(variable)
|
self._convert_value(variable)
|
||||||
|
|
||||||
@staticmethod
|
def _convert_value(self,
|
||||||
def _convert_value(variable,
|
variable,
|
||||||
variable_type: str=None,
|
variable_type: str=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
# a boolean must have value, the default value is "True"
|
||||||
|
if not hasattr(variable, 'value') and variable.type == 'boolean':
|
||||||
|
new_value = self.objectspace.value(variable.xmlfiles)
|
||||||
|
new_value.name = True
|
||||||
|
new_value.type = 'boolean'
|
||||||
|
variable.value = [new_value]
|
||||||
|
"""if the variable is mandatory and doesn't have any value
|
||||||
|
then the variable's mode is set to 'basic'
|
||||||
|
"""
|
||||||
|
# variable with default value is mandatory
|
||||||
|
if hasattr(variable, 'value') and variable.value:
|
||||||
|
has_value = True
|
||||||
|
for value in variable.value:
|
||||||
|
if value.type == 'calculation':
|
||||||
|
has_value = False
|
||||||
|
break
|
||||||
|
if has_value:
|
||||||
|
# if has value without any calculation
|
||||||
|
variable.mandatory = True
|
||||||
if not hasattr(variable, 'value'):
|
if not hasattr(variable, 'value'):
|
||||||
return
|
return
|
||||||
if variable.value[0].type == 'calculation':
|
if variable.value[0].type == 'calculation':
|
||||||
|
|
|
@ -240,7 +240,6 @@ class Variable(Common):
|
||||||
if hasattr(self.elt, key) and getattr(self.elt, key) is not None:
|
if hasattr(self.elt, key) and getattr(self.elt, key) is not None:
|
||||||
value = getattr(self.elt, key)
|
value = getattr(self.elt, key)
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
print('pouet')
|
|
||||||
value = self.convert_str(value)
|
value = self.convert_str(value)
|
||||||
elif isinstance(value, self.objectspace.value):
|
elif isinstance(value, self.objectspace.value):
|
||||||
value = self.calculation_value(value, [])
|
value = self.calculation_value(value, [])
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
<variables>
|
||||||
|
<family name="Général">
|
||||||
|
<variable name="condition" type="string" description="No change">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
<variable name="mode_conteneur_actif" type="string" description="No change" >
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
<variable name="mode_conteneur_actif2" type="string" description="No change">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
<family name="Général2">
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<condition name="hidden_if_in" source="condition">
|
||||||
|
<param>oui</param>
|
||||||
|
<target type="variable">mode_conteneur_actif</target>
|
||||||
|
<target type="variable">mode_conteneur_actif2</target>
|
||||||
|
<target type="family">Général2</target>
|
||||||
|
</condition>
|
||||||
|
</constraints>
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non"}
|
|
@ -0,0 +1,20 @@
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
from importlib.util import spec_from_loader, module_from_spec
|
||||||
|
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||||
|
spec = spec_from_loader(loader.name, loader)
|
||||||
|
func = module_from_spec(spec)
|
||||||
|
loader.exec_module(func)
|
||||||
|
for key, value in dict(locals()).items():
|
||||||
|
if key != ['SourceFileLoader', 'func']:
|
||||||
|
setattr(func, key, value)
|
||||||
|
try:
|
||||||
|
from tiramisu3 import *
|
||||||
|
except:
|
||||||
|
from tiramisu import *
|
||||||
|
from rougail.tiramisu import ConvertDynOptionDescription
|
||||||
|
option_3 = StrOption(name="condition", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
|
||||||
|
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('force_default_on_freeze'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))}))
|
||||||
|
option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('force_default_on_freeze'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))}))
|
||||||
|
option_2 = OptionDescription(name="general", doc="Général", children=[option_3, option_4, option_5], properties=frozenset({"normal"}))
|
||||||
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
Loading…
Reference in New Issue