Compare commits
No commits in common. "36827b686970b3176f1e62ecf0ff5580525cbf7b" and "a0fd998aeb65c82a890578e41fab901ab37f1a68" have entirely different histories.
36827b6869
...
a0fd998aeb
|
@ -120,7 +120,7 @@ class Annotator(Walk):
|
|||
obj,
|
||||
) -> None:
|
||||
modes_level = self.objectspace.rougailconfig['modes_level']
|
||||
if self._has_mode(obj) and obj.mode not in modes_level:
|
||||
if hasattr(obj, 'mode') and obj.mode not in modes_level:
|
||||
msg = _(f'mode "{obj.mode}" for "{obj.name}" is not a valid mode, '
|
||||
f'valid modes are {modes_level}')
|
||||
raise DictConsistencyError(msg, 71, obj.xmlfiles)
|
||||
|
@ -128,29 +128,23 @@ class Annotator(Walk):
|
|||
def _set_default_mode(self,
|
||||
family: 'self.objectspace.family',
|
||||
) -> None:
|
||||
if not hasattr(family, 'variable'):
|
||||
return
|
||||
if self._has_mode(family):
|
||||
if hasattr(family, 'mode') and 'mode' in vars(family):
|
||||
family_mode = family.mode
|
||||
else:
|
||||
family_mode = None
|
||||
leader = None
|
||||
if not hasattr(family, 'variable'):
|
||||
return
|
||||
for variable in family.variable.values():
|
||||
if leader is None and hasattr(family, 'leadership') and family.leadership:
|
||||
leader = variable
|
||||
self.valid_mode(variable)
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
# set default mode a subfamily
|
||||
if not variable.leadership:
|
||||
if family_mode and not self._has_mode(variable):
|
||||
self._set_auto_mode(variable, family_mode)
|
||||
continue
|
||||
func = self._set_default_mode_leader
|
||||
else:
|
||||
# set default mode to a variable
|
||||
self.valid_mode(variable)
|
||||
if leader:
|
||||
self._set_default_mode_leader(leader, variable)
|
||||
self._set_default_mode_variable(variable, family_mode)
|
||||
if leader:
|
||||
# here because follower can change leader mode
|
||||
self._set_auto_mode(family, leader.mode)
|
||||
func = self._set_default_mode_variable
|
||||
func(variable, family_mode)
|
||||
|
||||
@staticmethod
|
||||
def _has_mode(obj) -> bool:
|
||||
|
@ -180,25 +174,25 @@ class Annotator(Walk):
|
|||
obj.mode_auto = True
|
||||
|
||||
def _set_default_mode_leader(self,
|
||||
leader: 'self.objectspace.variable',
|
||||
follower: 'self.objectspace.variable',
|
||||
leadership: 'self.objectspace.family',
|
||||
family_mode: str,
|
||||
) -> None:
|
||||
leader_mode = None
|
||||
leader = next(iter(leadership.variable.values()))
|
||||
for follower in leadership.variable.values():
|
||||
self.valid_mode(follower)
|
||||
if follower.auto_save is True:
|
||||
msg = _(f'leader/followers "{follower.name}" could not be auto_save')
|
||||
raise DictConsistencyError(msg, 29, follower.xmlfiles)
|
||||
raise DictConsistencyError(msg, 29, leadership.xmlfiles)
|
||||
if follower.auto_freeze is True:
|
||||
msg = f'leader/followers "{follower.name}" could not be auto_freeze'
|
||||
raise DictConsistencyError(_(msg), 30, follower.xmlfiles)
|
||||
if leader == follower:
|
||||
# it's a leader
|
||||
if not hasattr(leader, 'mode'):
|
||||
self._set_auto_mode(leader, self.objectspace.rougailconfig['default_variable_mode'])
|
||||
return
|
||||
if self._has_mode(follower):
|
||||
raise DictConsistencyError(_(msg), 30, leadership.xmlfiles)
|
||||
if leader_mode is not None:
|
||||
if hasattr(follower, 'mode'):
|
||||
follower_mode = follower.mode
|
||||
else:
|
||||
follower_mode = self.objectspace.rougailconfig['default_variable_mode']
|
||||
if self.modes[leader.mode] > self.modes[follower_mode]:
|
||||
if self.modes[leader_mode] > self.modes[follower_mode]:
|
||||
if self._has_mode(follower) and not self._has_mode(leader):
|
||||
# if follower has mode but not the leader
|
||||
self._set_auto_mode(leader, follower_mode)
|
||||
|
@ -206,9 +200,20 @@ class Annotator(Walk):
|
|||
# leader's mode is minimum level
|
||||
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}"')
|
||||
f'but leader have the higher mode "{leader_mode}"')
|
||||
raise DictConsistencyError(msg, 63, follower.xmlfiles)
|
||||
self._set_auto_mode(follower, leader.mode)
|
||||
self._set_auto_mode(follower, leader_mode)
|
||||
self._set_default_mode_variable(follower,
|
||||
family_mode,
|
||||
)
|
||||
if leader_mode is None:
|
||||
if hasattr(leader, 'mode'):
|
||||
leader_mode = leader.mode
|
||||
else:
|
||||
leader_mode = self.objectspace.rougailconfig['default_variable_mode']
|
||||
if hasattr(leader, 'mode'):
|
||||
leader_mode = leader.mode
|
||||
self._set_auto_mode(leadership, leader_mode)
|
||||
|
||||
def _change_family_mode(self,
|
||||
family: 'self.objectspace.family',
|
||||
|
@ -219,41 +224,42 @@ class Annotator(Walk):
|
|||
family_mode = self.objectspace.rougailconfig['default_family_mode']
|
||||
min_variable_mode = self.objectspace.rougailconfig['modes_level'][-1]
|
||||
# change variable mode, but not if variables are not in a family
|
||||
is_leadership = hasattr(family, 'leadership') and family.leadership
|
||||
if hasattr(family, 'variable'):
|
||||
for idx, variable in enumerate(family.variable.values()):
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
if not hasattr(variable, 'mode'):
|
||||
variable.mode = self.objectspace.rougailconfig['default_family_mode']
|
||||
elif idx == 0 and is_leadership:
|
||||
variable.mode = None
|
||||
continue
|
||||
if variable.leadership:
|
||||
func = self._change_variable_mode_leader
|
||||
else:
|
||||
self._change_variable_mode(variable, family_mode, is_leadership)
|
||||
func = None
|
||||
else:
|
||||
func = self._change_variable_mode
|
||||
if func:
|
||||
func(variable,
|
||||
family_mode,
|
||||
)
|
||||
elif not hasattr(variable, 'mode'):
|
||||
variable.mode = self.objectspace.rougailconfig['default_family_mode']
|
||||
if self.modes[min_variable_mode] > self.modes[variable.mode]:
|
||||
min_variable_mode = variable.mode
|
||||
if not isinstance(family, self.objectspace.family) or is_leadership:
|
||||
# it's Variable, Service, ... and leadership
|
||||
return
|
||||
if not hasattr(family, 'mode'):
|
||||
if isinstance(family, self.objectspace.family) and \
|
||||
(not hasattr(family, 'mode') or family.mode != min_variable_mode):
|
||||
# set the lower variable mode to family
|
||||
self._set_auto_mode(family, min_variable_mode)
|
||||
if 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, family.xmlfiles)
|
||||
self._set_auto_mode(family, min_variable_mode)
|
||||
|
||||
def _change_variable_mode(self,
|
||||
variable,
|
||||
family_mode: str,
|
||||
is_follower: bool,
|
||||
) -> None:
|
||||
if hasattr(variable, 'mode'):
|
||||
variable_mode = variable.mode
|
||||
else:
|
||||
variable_mode = self.objectspace.rougailconfig['default_variable_mode']
|
||||
# none basic variable in high level family has to be in high level
|
||||
if not is_follower and self.modes[variable_mode] < self.modes[family_mode]:
|
||||
if self.modes[variable_mode] < self.modes[family_mode]:
|
||||
if self._has_mode(variable):
|
||||
msg = _(f'the variable "{variable.name}" is in "{variable_mode}" mode '
|
||||
f'but family has the higher family mode "{family_mode}"')
|
||||
|
@ -262,6 +268,18 @@ class Annotator(Walk):
|
|||
if not hasattr(variable, 'mode'):
|
||||
variable.mode = variable_mode
|
||||
|
||||
def _change_variable_mode_leader(self,
|
||||
leadership,
|
||||
family_mode: str,
|
||||
) -> None:
|
||||
for idx, follower in enumerate(leadership.variable.values()):
|
||||
if idx == 0:
|
||||
leader = follower
|
||||
self._change_variable_mode(follower,
|
||||
family_mode,
|
||||
)
|
||||
leader.mode = None
|
||||
|
||||
def dynamic_families(self):
|
||||
"""link dynamic families to object
|
||||
"""
|
||||
|
|
|
@ -47,7 +47,7 @@ class Annotator(Walk):
|
|||
"""convert groups
|
||||
"""
|
||||
# store old leaders family name
|
||||
for family in self.get_families():
|
||||
for family in self.get_families(with_leadership=True):
|
||||
if not isinstance(family, self.objectspace.family):
|
||||
continue
|
||||
if not family.leadership:
|
||||
|
@ -55,6 +55,7 @@ class Annotator(Walk):
|
|||
if hasattr(family, 'dynamic'):
|
||||
msg = _(f'the family "{family.name}" cannot be leadership and dynamic together')
|
||||
raise DictConsistencyError(msg, 31, family.xmlfiles)
|
||||
family.doc = family.description
|
||||
for idx, variable in enumerate(family.variable.values()):
|
||||
if idx == 0:
|
||||
# it's a leader
|
||||
|
@ -71,7 +72,3 @@ class Annotator(Walk):
|
|||
if family.hidden:
|
||||
variable.frozen = True
|
||||
variable.force_default_on_freeze = True
|
||||
if variable.multi is True:
|
||||
variable.multi = 'submulti'
|
||||
else:
|
||||
variable.multi = True
|
||||
|
|
|
@ -106,5 +106,8 @@ class Annotator(Walk):
|
|||
def convert_variable(self) -> None:
|
||||
"""convert variables
|
||||
"""
|
||||
for variable in self.get_variables():
|
||||
for variable in self.get_variables(with_leadership=True):
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
for follower in variable.variable.values():
|
||||
self.convert_property(follower)
|
||||
self.convert_property(variable)
|
||||
|
|
|
@ -45,11 +45,20 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
def convert_value(self) -> None:
|
||||
"""convert value
|
||||
"""
|
||||
for variable in self.get_variables():
|
||||
for variable in self.get_variables(with_leadership=True):
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
variable_type = 'leader'
|
||||
for follower in variable.variable.values():
|
||||
self._convert_value(follower,
|
||||
variable_type,
|
||||
)
|
||||
variable_type = 'follower'
|
||||
else:
|
||||
self._convert_value(variable)
|
||||
|
||||
def _convert_value(self,
|
||||
variable,
|
||||
variable_type: str=None,
|
||||
) -> None:
|
||||
# a boolean must have value, the default value is "True"
|
||||
if not hasattr(variable, 'value') and variable.type == 'boolean':
|
||||
|
@ -74,9 +83,9 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
if variable.value[0].type == 'calculation':
|
||||
variable.default = variable.value[0]
|
||||
elif variable.multi:
|
||||
if not self.objectspace.paths.is_follower(variable.path):
|
||||
if variable_type != 'follower':
|
||||
variable.default = [value.name for value in variable.value]
|
||||
if not self.objectspace.paths.is_leader(variable.path):
|
||||
if variable_type != 'leader':
|
||||
if variable.multi == 'submulti':
|
||||
variable.default_multi = [value.name for value in variable.value]
|
||||
else:
|
||||
|
|
|
@ -72,38 +72,45 @@ class Walk:
|
|||
"""
|
||||
objectspace = None
|
||||
|
||||
def get_variables(self):
|
||||
def get_variables(self,
|
||||
with_leadership: bool=False,
|
||||
):
|
||||
"""Iter all variables from the objectspace
|
||||
"""
|
||||
for family in self.objectspace.space.variables.values():
|
||||
yield from self._get_variables(family)
|
||||
yield from self._get_variables(family, with_leadership)
|
||||
|
||||
def _get_variables(self,
|
||||
family: 'self.objectspace.family',
|
||||
with_leadership: bool
|
||||
):
|
||||
if not hasattr(family, 'variable'):
|
||||
return
|
||||
if hasattr(family, 'variable'):
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
yield from self._get_variables(variable)
|
||||
else:
|
||||
if variable.leadership is False:
|
||||
yield from self._get_variables(variable, with_leadership)
|
||||
continue
|
||||
if not with_leadership:
|
||||
for follower in variable.variable.values():
|
||||
yield follower
|
||||
continue
|
||||
yield variable
|
||||
|
||||
def get_families(self):
|
||||
def get_families(self, with_leadership=False):
|
||||
"""Iter all families from the objectspace
|
||||
"""
|
||||
for family in self.objectspace.space.variables.values():
|
||||
yield from self._get_families(family)
|
||||
yield from self._get_families(family, with_leadership)
|
||||
|
||||
def _get_families(self,
|
||||
family: 'self.objectspace.family',
|
||||
with_leadership: bool,
|
||||
):
|
||||
yield family
|
||||
if not hasattr(family, 'variable'):
|
||||
return
|
||||
if hasattr(family, 'variable'):
|
||||
for fam in family.variable.values():
|
||||
if isinstance(fam, self.objectspace.family):
|
||||
yield from self._get_families(fam)
|
||||
if isinstance(fam, self.objectspace.family) and (with_leadership or not fam.leadership):
|
||||
yield from self._get_families(fam, with_leadership)
|
||||
|
||||
|
||||
class Annotator(Walk): # pylint: disable=R0903
|
||||
|
@ -127,11 +134,23 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
def convert_variable(self):
|
||||
"""convert variable
|
||||
"""
|
||||
for variable in self.get_variables():
|
||||
self._convert_variable(variable)
|
||||
for variable in self.get_variables(with_leadership=True):
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
# first variable is a leader, others are follower
|
||||
variable_type = 'leader'
|
||||
for follower in variable.variable.values():
|
||||
self._convert_variable(follower,
|
||||
variable_type,
|
||||
)
|
||||
variable_type = 'follower'
|
||||
else:
|
||||
self._convert_variable(variable,
|
||||
'variable',
|
||||
)
|
||||
|
||||
def _convert_variable(self,
|
||||
variable,
|
||||
variable_type: str,
|
||||
) -> None:
|
||||
if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \
|
||||
variable.name in self.forbidden_name:
|
||||
|
@ -156,6 +175,11 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
del variable.value
|
||||
variable.doc = variable.description
|
||||
del variable.description
|
||||
if variable_type == 'follower':
|
||||
if variable.multi is True:
|
||||
variable.multi = 'submulti'
|
||||
else:
|
||||
variable.multi = True
|
||||
self._convert_valid_enum(variable)
|
||||
|
||||
def _convert_valid_enum(self,
|
||||
|
@ -189,19 +213,21 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
"""Convert variable tests value
|
||||
"""
|
||||
for variable in self.get_variables():
|
||||
if not hasattr(variable, 'test') or not variable.test:
|
||||
# with we want remove test, we set "" has test value
|
||||
if not hasattr(variable, 'test'):
|
||||
continue
|
||||
if variable.test:
|
||||
if not hasattr(variable, 'information'):
|
||||
variable.information = self.objectspace.information(variable.xmlfiles)
|
||||
values = variable.test.split('|')
|
||||
new_values = []
|
||||
for value in variable.test.split('|'):
|
||||
for value in values:
|
||||
if value == '':
|
||||
value = None
|
||||
else:
|
||||
value = CONVERT_OPTION.get(variable.type, {}).get('func', str)(value)
|
||||
new_values.append(value)
|
||||
if not hasattr(variable, 'information'):
|
||||
variable.information = self.objectspace.information(variable.xmlfiles)
|
||||
variable.information.test = tuple(new_values)
|
||||
del variable.test
|
||||
|
||||
def convert_help(self):
|
||||
"""Convert variable help
|
||||
|
|
|
@ -38,7 +38,7 @@ FORCE_REDEFINABLES = ('family', 'follower', 'service', 'disknod', 'variables')
|
|||
# RougailObjSpace's elements that shall be forced to the UnRedefinable type
|
||||
FORCE_UNREDEFINABLES = ('value',)
|
||||
# RougailObjSpace's elements that shall not be modify
|
||||
UNREDEFINABLE = ('multi', 'type',)
|
||||
UNREDEFINABLE = ('multi', 'type', 'leadership')
|
||||
# RougailObjSpace's elements that did not created automaticly
|
||||
FORCE_ELEMENTS = ('choice', 'property_', 'information')
|
||||
# XML text are convert has name
|
||||
|
|
Loading…
Reference in New Issue