update mode
This commit is contained in:
parent
e35a3cb19d
commit
2e16bc2b90
|
@ -122,29 +122,44 @@ class FamilyAnnotator(Walk):
|
||||||
return
|
return
|
||||||
for variable in family.variable.values():
|
for variable in family.variable.values():
|
||||||
if isinstance(variable, self.objectspace.family):
|
if isinstance(variable, self.objectspace.family):
|
||||||
if family_mode and 'mode' not in vars(variable):
|
if family_mode and not self._has_mode(variable):
|
||||||
variable.mode = family_mode
|
self._set_auto_mode(variable, family_mode)
|
||||||
continue
|
continue
|
||||||
if isinstance(variable, self.objectspace.leadership):
|
if isinstance(variable, self.objectspace.leadership):
|
||||||
func = self._set_default_mode_leader
|
func = self._set_default_mode_leader
|
||||||
else:
|
else:
|
||||||
func = self._set_default_mode_variable
|
func = self._set_default_mode_variable
|
||||||
func(variable)
|
func(variable, family_mode)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _set_default_mode_variable(variable: 'self.objectspace.variable',
|
def _has_mode(obj) -> bool:
|
||||||
) -> None:
|
return 'mode' in vars(obj) and not hasattr(obj, 'mode_auto')
|
||||||
|
|
||||||
|
def _set_default_mode_variable(self,
|
||||||
|
variable: 'self.objectspace.variable',
|
||||||
|
family_mode: str,
|
||||||
|
) -> None:
|
||||||
# auto_save or auto_freeze variable is set to 'basic' mode
|
# auto_save or auto_freeze variable is set to 'basic' mode
|
||||||
# if its mode is not defined by the user
|
# if its mode is not defined by the user
|
||||||
if 'mode' not in vars(variable) and \
|
if not self._has_mode(variable) and \
|
||||||
(variable.auto_save is True or variable.auto_freeze is True):
|
(variable.auto_save is True or variable.auto_freeze is True):
|
||||||
variable.mode = modes_level[0]
|
self._set_auto_mode(variable, modes_level[0])
|
||||||
# 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, 'default'):
|
elif variable.mandatory is True and \
|
||||||
variable.mode = modes_level[0]
|
not hasattr(variable, 'default') and \
|
||||||
|
not hasattr(variable, 'default_multi'):
|
||||||
|
self._set_auto_mode(variable, modes_level[0])
|
||||||
|
elif family_mode and not self._has_mode(variable):
|
||||||
|
self._set_auto_mode(variable, family_mode)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _set_auto_mode(obj, mode: str) -> None:
|
||||||
|
obj.mode = mode
|
||||||
|
obj.mode_auto = True
|
||||||
|
|
||||||
def _set_default_mode_leader(self,
|
def _set_default_mode_leader(self,
|
||||||
leadership,
|
leadership: 'self.objectspace.leadership',
|
||||||
|
family_mode: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
leader_mode = None
|
leader_mode = None
|
||||||
for follower in leadership.variable:
|
for follower in leadership.variable:
|
||||||
|
@ -154,14 +169,23 @@ class FamilyAnnotator(Walk):
|
||||||
if follower.auto_freeze is True:
|
if follower.auto_freeze is True:
|
||||||
msg = f'leader/followers "{follower.name}" could not be auto_freeze'
|
msg = f'leader/followers "{follower.name}" could not be auto_freeze'
|
||||||
raise DictConsistencyError(_(msg), 30, leadership.xmlfiles)
|
raise DictConsistencyError(_(msg), 30, leadership.xmlfiles)
|
||||||
self._set_default_mode_variable(follower)
|
if leader_mode is not None:
|
||||||
if leader_mode is None:
|
|
||||||
leader_mode = leadership.variable[0].mode
|
|
||||||
else:
|
|
||||||
# leader's mode is minimum level
|
# leader's mode is minimum level
|
||||||
if modes[leader_mode] > modes[follower.mode]:
|
if modes[leader_mode] > modes[follower.mode]:
|
||||||
follower.mode = leader_mode
|
if self._has_mode(follower) and not self._has_mode(leadership.variable[0]):
|
||||||
leadership.mode = leader_mode
|
self._set_auto_mode(leadership.variable[0], follower.mode)
|
||||||
|
else:
|
||||||
|
if self._has_mode(follower):
|
||||||
|
msg = _(f'the follower "{follower.name}" is in "{follower.mode}" mode '
|
||||||
|
f'but leader have the higher mode "{leader_mode}"')
|
||||||
|
raise DictConsistencyError(msg, 63, follower.xmlfiles)
|
||||||
|
self._set_auto_mode(follower, leader_mode)
|
||||||
|
self._set_default_mode_variable(follower,
|
||||||
|
family_mode,
|
||||||
|
)
|
||||||
|
if leader_mode is None:
|
||||||
|
leader_mode = leadership.variable[0].mode
|
||||||
|
self._set_auto_mode(leadership, leadership.variable[0].mode)
|
||||||
|
|
||||||
def _change_family_mode(self,
|
def _change_family_mode(self,
|
||||||
family: 'self.objectspace.family',
|
family: 'self.objectspace.family',
|
||||||
|
@ -184,9 +208,13 @@ class FamilyAnnotator(Walk):
|
||||||
)
|
)
|
||||||
if modes[min_variable_mode] > modes[variable.mode]:
|
if modes[min_variable_mode] > modes[variable.mode]:
|
||||||
min_variable_mode = variable.mode
|
min_variable_mode = variable.mode
|
||||||
if hasattr(family, 'mode'):
|
if hasattr(family, 'mode') and family.mode != min_variable_mode:
|
||||||
# set the lower variable mode to family
|
# set the lower variable mode to family
|
||||||
family.mode = min_variable_mode
|
if self._has_mode(family):
|
||||||
|
msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and '
|
||||||
|
f'families inside have the higher modes "{min_variable_mode}"')
|
||||||
|
raise DictConsistencyError(msg, 62, variable.xmlfiles)
|
||||||
|
self._set_auto_mode(family, min_variable_mode)
|
||||||
|
|
||||||
def _change_variable_mode(self,
|
def _change_variable_mode(self,
|
||||||
variable,
|
variable,
|
||||||
|
@ -194,9 +222,12 @@ class FamilyAnnotator(Walk):
|
||||||
is_follower=False,
|
is_follower=False,
|
||||||
) -> None:
|
) -> None:
|
||||||
# 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]:
|
||||||
(not is_follower or variable.mode != modes_level[0]):
|
if self._has_mode(variable):
|
||||||
variable.mode = family_mode
|
msg = _(f'the variable "{variable.name}" is in "{variable.mode}" mode '
|
||||||
|
f'but family has the higher family mode "{family_mode}"')
|
||||||
|
raise DictConsistencyError(msg, 61, variable.xmlfiles)
|
||||||
|
self._set_auto_mode(variable, family_mode)
|
||||||
|
|
||||||
def _change_variable_mode_leader(self,
|
def _change_variable_mode_leader(self,
|
||||||
leadership,
|
leadership,
|
||||||
|
|
|
@ -11,8 +11,8 @@ try:
|
||||||
from tiramisu3 import *
|
from tiramisu3 import *
|
||||||
except:
|
except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
|
option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"basic", "mandatory"}))
|
||||||
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.calc_val, Params((ParamOption(option_4)))), properties=frozenset({"expert", "mandatory"}))
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.calc_val, Params((ParamOption(option_4)))), properties=frozenset({"expert", "mandatory"}))
|
||||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"normal"}))
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"basic"}))
|
||||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
||||||
|
|
|
@ -13,7 +13,7 @@ except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="oui", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="oui", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
|
||||||
option_5 = NetmaskOption(name="nut_monitor_netmask", doc="Masque de l'IP du réseau de l'esclave", multi=True)
|
option_5 = NetmaskOption(name="nut_monitor_netmask", doc="Masque de l'IP du réseau de l'esclave", multi=True)
|
||||||
option_6 = NetworkOption(name="nut_monitor_host", doc="Adresse IP du réseau de l'esclave", multi=True, properties=frozenset({"mandatory", "normal"}))
|
option_6 = NetworkOption(name="nut_monitor_host", doc="Adresse IP du réseau de l'esclave", multi=True, properties=frozenset({"basic", "mandatory"}))
|
||||||
option_4 = Leadership(name="nut_monitor_netmask", doc="Masque de l'IP du réseau de l'esclave", children=[option_5, option_6], properties=frozenset({"normal"}))
|
option_4 = Leadership(name="nut_monitor_netmask", doc="Masque de l'IP du réseau de l'esclave", children=[option_5, option_6], properties=frozenset({"normal"}))
|
||||||
option_2 = OptionDescription(name="general", doc="général", children=[option_3, option_4], properties=frozenset({"normal"}))
|
option_2 = OptionDescription(name="general", doc="général", children=[option_3, option_4], properties=frozenset({"normal"}))
|
||||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
<rougail>
|
<rougail>
|
||||||
<variables>
|
<variables>
|
||||||
<family name="general">
|
<family name="general">
|
||||||
<variable name="mode_conteneur_actif" type="string" description="leader" multi="True">
|
<variable name="mode_conteneur_actif" type="string" description="leader" multi="True">
|
||||||
<value>non</value>
|
<value>non</value>
|
||||||
</variable>
|
</variable>
|
||||||
<variable name="leader" type="string" description="leader" multi="True"/>
|
<variable name="leader" type="string" description="leader" multi="True"/>
|
||||||
<variable name="follower1" type="string" description="follower1">
|
<variable name="follower1" type="string" description="follower1">
|
||||||
<value>value</value>
|
<value>value</value>
|
||||||
</variable>
|
</variable>
|
||||||
<variable name="follower2" type="string" description="follower2"/>
|
<variable name="follower2" type="string" description="follower2"/>
|
||||||
</family>
|
</family>
|
||||||
</variables>
|
</variables>
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
<rougail>
|
<rougail>
|
||||||
<variables>
|
<variables>
|
||||||
<family name="general">
|
<family name="general">
|
||||||
<variable name="mode_conteneur_actif" type="string" description="leader" multi="True">
|
<variable name="mode_conteneur_actif" type="string" description="leader" multi="True">
|
||||||
<value>non</value>
|
<value>non</value>
|
||||||
</variable>
|
</variable>
|
||||||
<variable name="leader" type="string" description="leader" multi="True">
|
<variable name="leader" type="string" description="leader" multi="True">
|
||||||
<value>leader</value>
|
<value>leader</value>
|
||||||
</variable>
|
</variable>
|
||||||
<variable name="follower1" type="string" description="follower1" multi="True">
|
<variable name="follower1" type="string" description="follower1" multi="True">
|
||||||
<value>value</value>
|
<value>value</value>
|
||||||
</variable>
|
</variable>
|
||||||
<variable name="follower2" type="string" description="follower2" multi="True">
|
<variable name="follower2" type="string" description="follower2" multi="True">
|
||||||
<value>value1</value>
|
<value>value1</value>
|
||||||
<value>value2</value>
|
<value>value2</value>
|
||||||
</variable>
|
</variable>
|
||||||
</family>
|
</family>
|
||||||
</variables>
|
</variables>
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ except:
|
||||||
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
|
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
|
||||||
option_5 = StrOption(name="leader", doc="leader", multi=True)
|
option_5 = StrOption(name="leader", doc="leader", multi=True)
|
||||||
option_6 = StrOption(name="follower1", doc="follower1", multi=True, properties=frozenset({"normal"}))
|
option_6 = StrOption(name="follower1", doc="follower1", multi=True, properties=frozenset({"normal"}))
|
||||||
option_7 = StrOption(name="follower2", doc="follower2", multi=True, properties=frozenset({"normal"}))
|
option_7 = StrOption(name="follower2", doc="follower2", multi=True, properties=frozenset({"basic"}))
|
||||||
option_4 = Leadership(name="leader", doc="leader", children=[option_5, option_6, option_7], properties=frozenset({"normal"}))
|
option_4 = Leadership(name="leader", doc="leader", children=[option_5, option_6, option_7], properties=frozenset({"basic"}))
|
||||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"normal"}))
|
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"basic"}))
|
||||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
<variables>
|
||||||
|
<family name="base">
|
||||||
|
<family name="subfamily">
|
||||||
|
<variable name="variable" mode="basic"/>
|
||||||
|
</family>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.base.subfamily.variable": null}
|
|
@ -0,0 +1,18 @@
|
||||||
|
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 *
|
||||||
|
option_4 = StrOption(name="variable", doc="variable", properties=frozenset({"basic"}))
|
||||||
|
option_3 = OptionDescription(name="subfamily", doc="subfamily", children=[option_4], properties=frozenset({"basic"}))
|
||||||
|
option_2 = OptionDescription(name="base", doc="base", children=[option_3], properties=frozenset({"basic"}))
|
||||||
|
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
<variables>
|
||||||
|
<family name="général" mode="normal">
|
||||||
|
<variable name="mode_conteneur_actif" type="string" description="No change" auto_save="True" mode="expert">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
<variables>
|
||||||
|
<family name="general" mode="expert">
|
||||||
|
<variable name="mode_conteneur_actif" type="string" description="No change">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
<family name="leadermode">
|
||||||
|
<variable name="leader" type="string" description="leader" multi="True" mode="expert"/>
|
||||||
|
<variable name="follower1" type="string" description="follower1" mode="normal"/>
|
||||||
|
<variable name="follower2" type="string" description="follower2"/>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<fill name="calc_list">
|
||||||
|
<param name="valeur">valfill</param>
|
||||||
|
<target>leader</target>
|
||||||
|
</fill>
|
||||||
|
<group leader="leader">
|
||||||
|
<follower>follower1</follower>
|
||||||
|
<follower>follower2</follower>
|
||||||
|
</group>
|
||||||
|
</constraints>
|
||||||
|
</rougail>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
<variables>
|
||||||
|
<family name="base" mode="expert">
|
||||||
|
<family name="subfamily">
|
||||||
|
<variable name="variable" mode="basic"/>
|
||||||
|
</family>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
Loading…
Reference in New Issue