add in RougailConfig auto_freeze_variable

This commit is contained in:
2021-02-14 18:42:16 +01:00
parent ab3713383f
commit d1a39e5183
33 changed files with 148 additions and 176 deletions

View File

@ -35,8 +35,6 @@ from .target import TargetAnnotator
from .param import ParamAnnotator
from .variable import Walk
FREEZE_AUTOFREEZE_VARIABLE = 'module_instancie'
class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
"""Annotate condition
@ -72,35 +70,30 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
def convert_auto_freeze(self):
"""convert auto_freeze
only if FREEZE_AUTOFREEZE_VARIABLE == 'oui' this variable is frozen
only if auto_freeze_variable is True this variable is frozen
"""
for variable in self.get_variables():
self._convert_auto_freeze(variable)
def _convert_auto_freeze(self,
variable: 'self.objectspace.variable',
) -> None:
if not variable.auto_freeze:
return
if variable.namespace != RougailConfig['variable_namespace']:
msg = _(f'auto_freeze is not allowed in extra "{variable.namespace}"')
raise DictConsistencyError(msg, 49, variable.xmlfiles)
new_condition = self.objectspace.condition(variable.xmlfiles)
new_condition.name = 'auto_frozen_if_not_in'
new_condition.namespace = variable.namespace
new_condition.source = FREEZE_AUTOFREEZE_VARIABLE
new_param = self.objectspace.param(variable.xmlfiles)
new_param.text = 'oui'
new_condition.param = [new_param]
new_target = self.objectspace.target(variable.xmlfiles)
new_target.type = 'variable'
new_target.name = variable.name
new_condition.target = [new_target]
if not hasattr(self.objectspace.space, 'constraints'):
self.objectspace.space.constraints = self.objectspace.constraints(variable.xmlfiles)
if not hasattr(self.objectspace.space.constraints, 'condition'):
self.objectspace.space.constraints.condition = []
self.objectspace.space.constraints.condition.append(new_condition)
if not variable.auto_freeze:
continue
if variable.namespace != RougailConfig['variable_namespace']:
msg = _(f'auto_freeze is not allowed in extra "{variable.namespace}"')
raise DictConsistencyError(msg, 49, variable.xmlfiles)
new_condition = self.objectspace.condition(variable.xmlfiles)
new_condition.name = 'auto_frozen_if_not_in'
new_condition.namespace = variable.namespace
new_condition.source = RougailConfig['auto_freeze_variable']
new_param = self.objectspace.param(variable.xmlfiles)
new_param.text = True
new_condition.param = [new_param]
new_target = self.objectspace.target(variable.xmlfiles)
new_target.type = 'variable'
new_target.name = variable.name
new_condition.target = [new_target]
if not hasattr(self.objectspace.space, 'constraints'):
self.objectspace.space.constraints = self.objectspace.constraints(variable.xmlfiles)
if not hasattr(self.objectspace.space.constraints, 'condition'):
self.objectspace.space.constraints.condition = []
self.objectspace.space.constraints.condition.append(new_condition)
def check_source_target(self):
"""verify that source != target in condition

View File

@ -90,9 +90,6 @@ class Walk:
yield follower
continue
yield variable
# if hasattr(family, 'family'):
# for fam in family.family.values():
# yield from self._get_variables(fam, with_leadership)
def get_families(self):
"""Iter all families from the objectspace

View File

@ -39,6 +39,7 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
'destinations_dir': join(ROUGAILROOT, 'destinations'),
'tmp_dir': join(ROUGAILROOT, 'tmp'),
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
'variable_namespace': 'rougail',
'functions_file': join(ROUGAILROOT, 'functions.py'),
'variable_namespace': 'rougail',
'auto_freeze_variable': 'instanciated_module',
}