reorganise

This commit is contained in:
2021-01-26 13:33:54 +01:00
parent 0b8a6e399a
commit cbd11a29c2
11 changed files with 85 additions and 33 deletions

View File

@ -25,9 +25,9 @@ class SpaceAnnotator: # pylint: disable=R0903
FillAnnotator(objectspace,
eosfunc_file,
)
ValueAnnotator(objectspace)
FamilyAnnotator(objectspace)
PropertyAnnotator(objectspace)
ValueAnnotator(objectspace)
__all__ = ('SpaceAnnotator', 'CONVERT_OPTION', 'modes')

View File

@ -196,7 +196,9 @@ class ConditionAnnotator:
variable = self.objectspace.paths.get_family(target.name.path,
target.namespace,
)
return variable, list(variable.variable.values())
if hasattr(variable, 'variable'):
return variable, list(variable.variable.values())
return variable, []
def convert_condition_source(self):
"""remove condition for ChoiceOption that don't have param

View File

@ -132,39 +132,13 @@ class FamilyAnnotator:
family_mode: str,
is_follower=False,
) -> 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
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]
# none basic variable in high level family has to be in high level
if modes[variable.mode] < modes[family_mode] and \
(not is_follower or variable.mode != modes_level[0]):
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):
"""change mode of a family

View File

@ -26,9 +26,15 @@ class PropertyAnnotator:
) -> None:
"""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'):
variable.properties = []
for prop in PROPERTIES:
if hasattr(variable, prop):
if getattr(variable, prop) is True:

View File

@ -17,6 +17,8 @@ class ValueAnnotator: # pylint: disable=R0903
"""
for families in self.objectspace.space.variables.values():
for family in families.family.values():
if not hasattr(family, 'variable'):
continue
for variable in family.variable.values():
if isinstance(variable, self.objectspace.leadership):
variable_type = 'leader'
@ -28,10 +30,29 @@ class ValueAnnotator: # pylint: disable=R0903
else:
self._convert_value(variable)
@staticmethod
def _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':
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'):
return
if variable.value[0].type == 'calculation':

View File

@ -240,7 +240,6 @@ class Variable(Common):
if hasattr(self.elt, key) and getattr(self.elt, key) is not None:
value = getattr(self.elt, key)
if isinstance(value, str):
print('pouet')
value = self.convert_str(value)
elif isinstance(value, self.objectspace.value):
value = self.calculation_value(value, [])