This commit is contained in:
Emmanuel Garette 2020-07-06 21:35:25 +02:00
parent 38c95ea87a
commit eb6b22e5b1
21 changed files with 85 additions and 83 deletions

View File

@ -299,18 +299,14 @@ class SpaceAnnotator(object):
self.objectspace = objectspace
self.valid_enums = {}
self.force_value = {}
self.has_calc = []
self.force_no_value = []
self.force_not_mandatory = []
if eosfunc_file:
self.eosfunc = imp.load_source('eosfunc', eosfunc_file)
else:
self.eosfunc = None
if HIGH_COMPATIBILITY:
self.default_has_no_value = []
self.has_frozen_if_in_condition = []
self.default_variable_options()
self.variable_submulti()
self.convert_variable()
self.convert_auto_freeze()
self.convert_groups()
self.filter_check()
@ -519,53 +515,35 @@ class SpaceAnnotator(object):
varpath = self.paths.get_variable_path(family.dynamic, namespace)
family.dynamic = varpath
def _annotate_variable(self, variable, family_mode, path, is_follower=False):
if (HIGH_COMPATIBILITY and variable.type == 'choice' and variable.mode != modes_level[-1] and variable.mandatory is True and path in self.default_has_no_value):
variable.mode = modes_level[0]
if variable.type == 'choice' and is_follower and family_mode == modes_level[0] and variable.mandatory is True:
variable.mode = modes_level[0]
def annotate_variable(self, variable, family_mode, path, is_follower=False):
# if the variable is mandatory and doesn't have any value
# then the variable's mode is set to 'basic'
has_value = hasattr(variable, 'value') and variable.value != None
if (path not in self.has_calc and variable.mandatory is True and
(not has_value or is_follower) and variable.type != 'choice'):
has_value = hasattr(variable, 'value')
if variable.mandatory is True and (not has_value or is_follower):
variable.mode = modes_level[0]
if has_value:
if not HIGH_COMPATIBILITY or (not path.startswith(f'{VARIABLE_NAMESPACE}.services.') \
and path not in self.force_no_value and path not in self.force_not_mandatory):
variable.mandatory = True
if variable.mode != None and modes[variable.mode] < modes[family_mode] and (not is_follower or variable.mode != modes_level[0]):
variable.mode = family_mode
if has_value and path not in self.force_not_mandatory:
variable.mandatory = True
if variable.hidden is True:
variable.frozen = True
if not variable.auto_save is True and 'force_default_on_freeze' not in vars(variable):
variable.force_default_on_freeze = True
if variable.name == 'frozen' and not variable.auto_save is True:
variable.force_default_on_freeze = True
if variable.mode != None and not is_follower and modes[variable.mode] < modes[family_mode]:
variable.mode = family_mode
if variable.mode != None and variable.mode != modes_level[0] and modes[variable.mode] < modes[family_mode]:
variable.mode = family_mode
def default_variable_options(self):
if hasattr(self.space, 'variables'):
for families in self.space.variables.values():
if hasattr(families, 'family'):
for family in families.family.values():
if hasattr(family, 'variable'):
for variable in family.variable.values():
if not hasattr(variable, 'type'):
variable.type = 'string'
if variable.type != 'symlink' and not hasattr(variable, 'description'):
variable.description = variable.name
def variable_submulti(self):
if hasattr(self.space, 'variables'):
for families in self.space.variables.values():
if hasattr(families, 'family'):
for family in families.family.values():
if hasattr(family, 'variable'):
for variable in family.variable.values():
if variable.submulti:
variable.multi = 'submulti'
def convert_variable(self):
if not hasattr(self.space, 'variables'):
return
for families in self.space.variables.values():
if hasattr(families, 'family'):
for family in families.family.values():
if hasattr(family, 'variable'):
for variable in family.variable.values():
if not hasattr(variable, 'type'):
variable.type = 'string'
if variable.type != 'symlink' and not hasattr(variable, 'description'):
variable.description = variable.name
if variable.submulti:
variable.multi = 'submulti'
def convert_auto_freeze(self): # pylint: disable=C0111
if hasattr(self.space, 'variables'):
@ -584,7 +562,6 @@ class SpaceAnnotator(object):
new_condition.param = [new_param]
new_target = self.objectspace.target()
new_target.type = 'variable'
print(variables.name, VARIABLE_NAMESPACE)
if variables.name == VARIABLE_NAMESPACE:
path = variable.name
else:
@ -596,41 +573,37 @@ class SpaceAnnotator(object):
self.space.constraints.condition.append(new_condition)
def _set_valid_enum(self, variable, values, type_):
if isinstance(values, list):
variable.mandatory = True
variable.choice = []
choices = []
for value in values:
choice = self.objectspace.choice()
try:
if type_ in CONVERSION:
choice.name = CONVERSION[type_](value)
else:
choice.name = str(value)
except:
raise CreoleDictConsistencyError(_(f'unable to change type of a valid_enum entry "{value}" is not a valid "{type_}" for "{variable.name}"'))
choices.append(choice.name)
choice.type = type_
variable.choice.append(choice)
if not variable.choice:
raise CreoleDictConsistencyError(_('empty valid enum is not allowed for variable {}').format(variable.name))
if hasattr(variable, 'value'):
for value in variable.value:
value.type = type_
if type_ in CONVERSION:
cvalue = CONVERSION[type_](value.name)
else:
cvalue = value.name
if cvalue not in choices:
raise CreoleDictConsistencyError(_('value "{}" of variable "{}" is not in list of all expected values ({})').format(value.name, variable.name, choices))
else:
new_value = self.objectspace.value()
new_value.name = values[0]
new_value.type = type_
variable.value = [new_value]
variable.mandatory = True
variable.choice = []
choices = []
for value in values:
choice = self.objectspace.choice()
try:
if type_ in CONVERSION:
choice.name = CONVERSION[type_](value)
else:
choice.name = str(value)
except:
raise CreoleDictConsistencyError(_(f'unable to change type of a valid_enum entry "{value}" is not a valid "{type_}" for "{variable.name}"'))
choices.append(choice.name)
choice.type = type_
variable.choice.append(choice)
if not variable.choice:
raise CreoleDictConsistencyError(_('empty valid enum is not allowed for variable {}').format(variable.name))
if hasattr(variable, 'value'):
for value in variable.value:
value.type = type_
if type_ in CONVERSION:
cvalue = CONVERSION[type_](value.name)
else:
cvalue = value.name
if cvalue not in choices:
raise CreoleDictConsistencyError(_('value "{}" of variable "{}" is not in list of all expected values ({})').format(value.name, variable.name, choices))
else:
# probe choice
variable.choice = values
new_value = self.objectspace.value()
new_value.name = values[0]
new_value.type = type_
variable.value = [new_value]
variable.type = 'choice'
def _convert_valid_enum(self, variable, path):
@ -694,7 +667,7 @@ class SpaceAnnotator(object):
else:
is_follower = False
path = '{}.{}.{}'.format(family.path, variable.name, follower.name)
self._annotate_variable(follower, family_mode, path, is_follower)
self.annotate_variable(follower, family_mode, path, is_follower)
# leader's mode is minimum level
if modes[variable.variable[0].mode] > modes[follower.mode]:
follower.mode = variable.variable[0].mode
@ -707,7 +680,7 @@ class SpaceAnnotator(object):
if variable.auto_freeze is True and variable.mode != modes_level[-1]:
variable.mode = modes_level[0]
path = '{}.{}'.format(family.path, variable.name)
self._annotate_variable(variable, family_mode, path)
self.annotate_variable(variable, family_mode, path)
def convert_fill(self): # pylint: disable=C0111,R0912
if not hasattr(self.space, 'constraints') or not hasattr(self.space.constraints, 'fill'):
@ -764,8 +737,6 @@ class SpaceAnnotator(object):
value.param = fill.param
variable = self.paths.get_variable_obj(fill.target)
variable.value = [value]
self.force_not_mandatory.append(fill.target)
self.has_calc.append(fill.target)
del self.space.constraints.fill
def filter_separators(self): # pylint: disable=C0111,R0201

View File

@ -7,6 +7,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="number">3</param>

View File

@ -17,6 +17,7 @@
<property>force_store_value</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>basic</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="string">oui</param>

View File

@ -15,6 +15,7 @@
</variable>
<variable doc="autosave variable" multi="False" name="autosavevar" type="string">
<property>force_store_value</property>
<property>mandatory</property>
<property>basic</property>
<property expected="oui" inverse="False" source="rougail.general.mode_conteneur_actif" type="calculation">frozen</property>
<property expected="oui" inverse="False" source="rougail.general.mode_conteneur_actif" type="calculation">hidden</property>

View File

@ -17,12 +17,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general1.leader.follower1</param>

View File

@ -17,6 +17,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
@ -26,6 +27,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.follower1</param>
@ -35,6 +37,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.leader</param>

View File

@ -17,6 +17,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
@ -26,6 +27,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.leader</param>

View File

@ -19,6 +19,7 @@
<variable doc="leader" multi="True" name="leader" type="string">
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>mandatory</property>
<value name="calc_list" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>

View File

@ -14,12 +14,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>expert</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.follower1</param>

View File

@ -14,12 +14,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.follower1</param>

View File

@ -16,12 +16,14 @@
<property>mandatory</property>
</variable>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.follower1</param>

View File

@ -21,6 +21,7 @@
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general.leader.follower1</param>

View File

@ -17,12 +17,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general1.leader.follower1</param>

View File

@ -17,12 +17,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general1.leader.follower1</param>

View File

@ -17,12 +17,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="True" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general1.leader.follower1</param>

View File

@ -17,12 +17,14 @@
<property>normal</property>
<variable doc="leader" multi="True" name="leader" type="string"/>
<variable doc="follower1" multi="True" name="follower1" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param name="valeur" transitive="False" type="string">valfill</param>
</value>
</variable>
<variable doc="follower2" multi="submulti" name="follower2" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="variable">rougail.general1.leader.follower1</param>

View File

@ -21,6 +21,7 @@
<family doc="new" name="new">
<property>normal</property>
<variable doc="No change" multi="False" name="newvar" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param suffix="val1" transitive="False" type="variable">rougail.dyn.vardyn</param>

View File

@ -7,6 +7,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="string">value</param>

View File

@ -4,6 +4,7 @@
<family doc="general" name="general">
<property>normal</property>
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="string">
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="string">value</param>

View File

@ -24,6 +24,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<property expected="oui" inverse="False" source="rougail.general.condition" type="calculation">disabled</property>
<value name="calc_val" type="calculation">

View File

@ -28,6 +28,7 @@
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value name="calc_val" type="calculation">
<param transitive="False" type="string">http://localhost/</param>