This commit is contained in:
Emmanuel Garette 2021-02-18 17:00:12 +01:00
parent 88f5b20aa9
commit 493aeff04e
14 changed files with 62 additions and 39 deletions

View file

@ -24,7 +24,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from typing import List, Any from typing import List
from ..i18n import _ from ..i18n import _
@ -115,7 +115,8 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
continue continue
remove_conditions.append(idx) remove_conditions.append(idx)
if (hasattr(condition, 'apply_on_fallback') and condition.apply_on_fallback) or \ if (hasattr(condition, 'apply_on_fallback') and condition.apply_on_fallback) or \
(not hasattr(condition, 'apply_on_fallback') and condition.name.endswith('_if_in')): (not hasattr(condition, 'apply_on_fallback') and \
condition.name.endswith('_if_in')):
self.force_actions_to_variable(condition) self.force_actions_to_variable(condition)
remove_conditions.sort(reverse=True) remove_conditions.sort(reverse=True)
for idx in remove_conditions: for idx in remove_conditions:
@ -242,9 +243,6 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
for param in condition.param: for param in condition.param:
if param_type is None or param_type == 'nil': if param_type is None or param_type == 'nil':
param_type = param.type param_type = param.type
if param_type != param.type:
msg = _(f'param with type "{target.type}" has multi param types')
raise DictConsistencyError(msg, 59, condition.xmlfiles)
param3 = self.objectspace.param(target.xmlfiles) param3 = self.objectspace.param(target.xmlfiles)
param3.name = f'condition_{fill.index}' param3.name = f'condition_{fill.index}'
param3.type = 'variable' param3.type = 'variable'

View file

@ -213,7 +213,7 @@ class FamilyAnnotator(Walk):
if self._has_mode(family): if self._has_mode(family):
msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and ' msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and '
f'families inside have the higher modes "{min_variable_mode}"') f'families inside have the higher modes "{min_variable_mode}"')
raise DictConsistencyError(msg, 62, variable.xmlfiles) raise DictConsistencyError(msg, 62, family.xmlfiles)
self._set_auto_mode(family, min_variable_mode) self._set_auto_mode(family, min_variable_mode)
def _change_variable_mode(self, def _change_variable_mode(self,

View file

@ -33,9 +33,14 @@ from ..error import DictConsistencyError
class ParamAnnotator: class ParamAnnotator:
def valid_type_validation(self, """Param annotator
obj, """
) -> None: objectspace = None
@staticmethod
def valid_type_validation(obj) -> None:
"""Function to valid type (redefine in fill/condition/check classes)
"""
return None return None
def convert_param(self, objects) -> None: def convert_param(self, objects) -> None:
@ -51,7 +56,7 @@ class ParamAnnotator:
if param.type in ['suffix', 'index']: if param.type in ['suffix', 'index']:
msg = _(f'"{param.type}" parameter must not have a value') msg = _(f'"{param.type}" parameter must not have a value')
raise DictConsistencyError(msg, 28, obj.xmlfiles) raise DictConsistencyError(msg, 28, obj.xmlfiles)
elif param.type == 'nil': if param.type == 'nil':
if param.text is not None: if param.text is not None:
msg = _(f'"{param.type}" parameter must not have a value') msg = _(f'"{param.type}" parameter must not have a value')
raise DictConsistencyError(msg, 40, obj.xmlfiles) raise DictConsistencyError(msg, 40, obj.xmlfiles)
@ -62,13 +67,15 @@ class ParamAnnotator:
) )
param.text = self.objectspace.paths.get_variable(path) param.text = self.objectspace.paths.get_variable(path)
if variable_type and param.text.type != variable_type: if variable_type and param.text.type != variable_type:
msg = _(f'"{obj.name}" has type "{variable_type}" but param has type "{param.text.type}"') msg = _(f'"{obj.name}" has type "{variable_type}" but param '
f'has type "{param.text.type}"')
raise DictConsistencyError(msg, 26, param.xmlfiles) raise DictConsistencyError(msg, 26, param.xmlfiles)
if suffix: if suffix:
param.suffix = suffix param.suffix = suffix
family_path = self.objectspace.paths.get_variable_family_path(path) family_path = self.objectspace.paths.get_variable_family_path(path)
namespace = param.text.namespace
param.family = self.objectspace.paths.get_family(family_path, param.family = self.objectspace.paths.get_family(family_path,
param.text.namespace, namespace,
) )
except DictConsistencyError as err: except DictConsistencyError as err:
if err.errno != 42 or not param.optional: if err.errno != 42 or not param.optional:
@ -81,16 +88,15 @@ class ParamAnnotator:
if param.type == 'suffix': if param.type == 'suffix':
for target in obj.target: for target in obj.target:
if not self.objectspace.paths.variable_is_dynamic(target.name.path): if not self.objectspace.paths.variable_is_dynamic(target.name.path):
msg = _(f'"{param.type}" parameter cannot be set with target "{target.name}"' msg = _(f'"{param.type}" parameter cannot be set with target '
f' which is not a dynamic variable') f'"{target.name}" which is not a dynamic variable')
raise DictConsistencyError(msg, 53, obj.xmlfiles) raise DictConsistencyError(msg, 53, obj.xmlfiles)
elif param.type == 'index': elif param.type == 'index':
for target in obj.target: for target in obj.target:
if not self.objectspace.paths.is_follower(target.name.path): if not self.objectspace.paths.is_follower(target.name.path):
msg = _(f'"{param.type}" parameter cannot be set with target "{target.name.name}"' msg = _(f'"{param.type}" parameter cannot be set with target '
f' which is not a follower variable') f'"{target.name.name}" which is not a follower variable')
raise DictConsistencyError(msg, 60, obj.xmlfiles) raise DictConsistencyError(msg, 60, obj.xmlfiles)
pass
elif param.type == 'nil': elif param.type == 'nil':
param.text = None param.text = None
elif param.type == 'string': elif param.type == 'string':
@ -104,8 +110,8 @@ class ParamAnnotator:
for param_idx in param_to_delete: for param_idx in param_to_delete:
obj.param.pop(param_idx) obj.param.pop(param_idx)
def _convert_with_variable_type(self, @staticmethod
variable_type: str, def _convert_with_variable_type(variable_type: str,
param: 'self.objectspace.param', param: 'self.objectspace.param',
) -> None: ) -> None:
if 'type' in vars(param) and variable_type != param.type: if 'type' in vars(param) and variable_type != param.type:
@ -115,7 +121,11 @@ class ParamAnnotator:
try: try:
option = CONVERT_OPTION[variable_type] option = CONVERT_OPTION[variable_type]
param.text = option.get('func', str)(param.text) param.text = option.get('func', str)(param.text)
getattr(tiramisu, option['opttype'])('test', 'Object to valid value', param.text, **option.get('initkwargs', {})) getattr(tiramisu, option['opttype'])('test',
'Object to valid value',
param.text,
**option.get('initkwargs', {}),
)
except ValueError as err: except ValueError as err:
msg = _(f'unable to change type of value "{param.text}" ' msg = _(f'unable to change type of value "{param.text}" '
f'is not a valid "{variable_type}"') f'is not a valid "{variable_type}"')

View file

@ -95,12 +95,14 @@ class PropertyAnnotator(Walk):
self.convert_property(variable) self.convert_property(variable)
def convert_family(self) -> None: def convert_family(self) -> None:
"""convert variables """convert families
""" """
for family in self.get_families(): for family in self.get_families():
self.convert_property(family) self.convert_property(family)
def convert_variable(self) -> None: def convert_variable(self) -> None:
"""convert variables
"""
for variable in self.get_variables(with_leadership=True): for variable in self.get_variables(with_leadership=True):
if isinstance(variable, self.objectspace.leadership): if isinstance(variable, self.objectspace.leadership):
for follower in variable.variable: for follower in variable.variable:

View file

@ -234,8 +234,8 @@ class ServiceAnnotator:
service_name, service_name,
) )
def _update_file(self, @staticmethod
file_, def _update_file(file_,
service_name, service_name,
): ):
if not hasattr(file_, 'file_type') or file_.file_type == "filename": if not hasattr(file_, 'file_type') or file_.file_type == "filename":

View file

@ -29,6 +29,8 @@ from ..error import DictConsistencyError
class TargetAnnotator: class TargetAnnotator:
"""Target annotator
"""
def convert_target(self, def convert_target(self,
objects, objects,
) -> None: ) -> None:
@ -62,7 +64,11 @@ class TargetAnnotator:
f'is not allowed') f'is not allowed')
raise DictConsistencyError(msg, 8, obj.xmlfiles) raise DictConsistencyError(msg, 8, obj.xmlfiles)
if target.type == 'family': if target.type == 'family':
if obj.name not in ['disabled_if_in', 'disabled_if_not_in', "hidden_if_in", "hidden_if_not_in"]: if obj.name not in ['disabled_if_in',
'disabled_if_not_in',
'hidden_if_in',
'hidden_if_not_in',
]:
msg = _(f'target "{target.type}" not allow with "{obj.name}"') msg = _(f'target "{target.type}" not allow with "{obj.name}"')
raise DictConsistencyError(msg, 51, target.xmlfiles) raise DictConsistencyError(msg, 51, target.xmlfiles)
target.name = self.objectspace.paths.get_family(target.name, target.name = self.objectspace.paths.get_family(target.name,

View file

@ -61,9 +61,8 @@ class ValueAnnotator(Walk): # pylint: disable=R0903
new_value.name = True new_value.name = True
new_value.type = 'boolean' new_value.type = 'boolean'
variable.value = [new_value] variable.value = [new_value]
"""if the variable is mandatory and doesn't have any value # if the variable is mandatory and doesn't have any value
then the variable's mode is set to 'basic' # then the variable's mode is set to 'basic'
"""
# variable with default value is mandatory # variable with default value is mandatory
if hasattr(variable, 'value') and variable.value: if hasattr(variable, 'value') and variable.value:
has_value = True has_value = True

View file

@ -70,6 +70,8 @@ FORCE_CHOICE = {'schedule': ['none', 'daily', 'weekly', 'monthly'],
class Walk: class Walk:
"""Walk to objectspace to find variable or family """Walk to objectspace to find variable or family
""" """
objectspace = None
def get_variables(self, def get_variables(self,
with_leadership: bool=False, with_leadership: bool=False,
): ):
@ -148,7 +150,8 @@ class VariableAnnotator(Walk): # pylint: disable=R0903
) -> None: ) -> None:
if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \ if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \
variable.name in self.forbidden_name: variable.name in self.forbidden_name:
msg = _(f'the name of the variable "{variable.name}" cannot be the same as the name of a namespace') msg = _(f'the name of the variable "{variable.name}" cannot be the same as the name'
' of a namespace')
raise DictConsistencyError(msg, 54, variable.xmlfiles) raise DictConsistencyError(msg, 54, variable.xmlfiles)
if variable.type != 'symlink' and not hasattr(variable, 'description'): if variable.type != 'symlink' and not hasattr(variable, 'description'):
variable.description = variable.name variable.description = variable.name

View file

@ -89,8 +89,8 @@ class RougailConvert:
functions_file, functions_file,
).get_text() + '\n' ).get_text() + '\n'
def _load_dictionaries(self, @staticmethod
xmlreflector: XMLReflector, def _load_dictionaries(xmlreflector: XMLReflector,
rougailobjspace: RougailObjSpace, rougailobjspace: RougailObjSpace,
namespace: str, namespace: str,
xmlfolders: List[str], xmlfolders: List[str],

View file

@ -56,7 +56,8 @@ class Path:
if namespace == self.variable_namespace: if namespace == self.variable_namespace:
full_name = '.'.join([subpath, name]) full_name = '.'.join([subpath, name])
if name in self.full_paths_families: if name in self.full_paths_families:
raise DictConsistencyError(_(f'Duplicate family name "{name}"'), 55, variableobj.xmlfiles) msg = _(f'Duplicate family name "{name}"')
raise DictConsistencyError(msg, 55, variableobj.xmlfiles)
self.full_paths_families[name] = full_name self.full_paths_families[name] = full_name
else: else:
if '.' not in name: # pragma: no cover if '.' not in name: # pragma: no cover
@ -65,7 +66,8 @@ class Path:
full_name = name full_name = name
if full_name in self.families and \ if full_name in self.families and \
self.families[full_name]['variableobj'] != variableobj: # pragma: no cover self.families[full_name]['variableobj'] != variableobj: # pragma: no cover
raise DictConsistencyError(_(f'Duplicate family name "{name}"'), 37, variableobj.xmlfiles) msg = _(f'Duplicate family name "{name}"')
raise DictConsistencyError(msg, 37, variableobj.xmlfiles)
if full_name in self.variables: if full_name in self.variables:
msg = _(f'A variable and a family has the same path "{full_name}"') msg = _(f'A variable and a family has the same path "{full_name}"')
raise DictConsistencyError(msg, 56, variableobj.xmlfiles) raise DictConsistencyError(msg, 56, variableobj.xmlfiles)

View file

@ -347,9 +347,9 @@ class RougailTemplate:
chdir(self.templates_dir) chdir(self.templates_dir)
for option in await self.config.option.list(type='all'): for option in await self.config.option.list(type='all'):
namespace = await option.option.name() namespace = await option.option.name()
is_variable_namespace = namespace == self.rougailconfig['variable_namespace'] is_var_namespace = namespace == self.rougailconfig['variable_namespace']
self.rougail_variables_dict[namespace] = await self.load_variables(option, self.rougail_variables_dict[namespace] = await self.load_variables(option,
is_variable_namespace, is_var_namespace,
) )
for template in listdir('.'): for template in listdir('.'):
self.prepare_template(template) self.prepare_template(template)
@ -396,6 +396,7 @@ class RougailTemplate:
variables[await option.option.name()] = subfamilies variables[await option.option.name()] = subfamilies
else: else:
if is_variable_namespace: if is_variable_namespace:
self.rougail_variables_dict[await option.option.name()] = await option.value.get() value = await option.value.get()
self.rougail_variables_dict[await option.option.name()] = value
variables[await option.option.name()] = await option.value.get() variables[await option.option.name()] = await option.value.get()
return RougailExtra(variables) return RougailExtra(variables)

View file

@ -72,7 +72,7 @@ class TiramisuReflector:
]) ])
self.objectspace = objectspace self.objectspace = objectspace
self.make_tiramisu_objects() self.make_tiramisu_objects()
if self.objectspace.has_dyn_option == True: if self.objectspace.has_dyn_option is True:
self.text.append("from rougail.tiramisu import ConvertDynOptionDescription") self.text.append("from rougail.tiramisu import ConvertDynOptionDescription")
def make_tiramisu_objects(self) -> None: def make_tiramisu_objects(self) -> None:
@ -95,8 +95,9 @@ class TiramisuReflector:
because `extra` family could use `variable_namespace` variables. because `extra` family could use `variable_namespace` variables.
""" """
if hasattr(self.objectspace.space, 'variables'): if hasattr(self.objectspace.space, 'variables'):
if self.objectspace.rougailconfig['variable_namespace'] in self.objectspace.space.variables: variable_namespace = self.objectspace.rougailconfig['variable_namespace']
yield self.objectspace.space.variables[self.objectspace.rougailconfig['variable_namespace']] if variable_namespace in self.objectspace.space.variables:
yield self.objectspace.space.variables[variable_namespace]
for elt, value in self.objectspace.space.variables.items(): for elt, value in self.objectspace.space.variables.items():
if elt != self.objectspace.rougailconfig['variable_namespace']: if elt != self.objectspace.rougailconfig['variable_namespace']:
yield value yield value

View file

@ -18,6 +18,7 @@
<param>a</param> <param>a</param>
<param>b</param> <param>b</param>
<param type="nil"/> <param type="nil"/>
<param></param>
<target>enumvar</target> <target>enumvar</target>
</check> </check>
</constraints> </constraints>

View file

@ -13,7 +13,7 @@ except:
from tiramisu import * from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"})) option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', None), default="b", properties=frozenset({"expert", "mandatory"})) option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', None, ''), default="b", properties=frozenset({"expert", "mandatory"}))
option_5.impl_set_information('help', "bla bla bla") option_5.impl_set_information('help', "bla bla bla")
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"})) option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4]) option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])