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
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
from typing import List, Any
from typing import List
from ..i18n import _
@ -115,7 +115,8 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
continue
remove_conditions.append(idx)
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)
remove_conditions.sort(reverse=True)
for idx in remove_conditions:
@ -242,9 +243,6 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
for param in condition.param:
if param_type is None or param_type == 'nil':
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.name = f'condition_{fill.index}'
param3.type = 'variable'

View File

@ -213,7 +213,7 @@ class FamilyAnnotator(Walk):
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, variable.xmlfiles)
raise DictConsistencyError(msg, 62, family.xmlfiles)
self._set_auto_mode(family, min_variable_mode)
def _change_variable_mode(self,

View File

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

View File

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

View File

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

View File

@ -29,6 +29,8 @@ from ..error import DictConsistencyError
class TargetAnnotator:
"""Target annotator
"""
def convert_target(self,
objects,
) -> None:
@ -62,7 +64,11 @@ class TargetAnnotator:
f'is not allowed')
raise DictConsistencyError(msg, 8, obj.xmlfiles)
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}"')
raise DictConsistencyError(msg, 51, target.xmlfiles)
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.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'
"""
# 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

View File

@ -70,6 +70,8 @@ FORCE_CHOICE = {'schedule': ['none', 'daily', 'weekly', 'monthly'],
class Walk:
"""Walk to objectspace to find variable or family
"""
objectspace = None
def get_variables(self,
with_leadership: bool=False,
):
@ -148,7 +150,8 @@ class VariableAnnotator(Walk): # pylint: disable=R0903
) -> None:
if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \
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)
if variable.type != 'symlink' and not hasattr(variable, 'description'):
variable.description = variable.name

View File

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

View File

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

View File

@ -347,9 +347,9 @@ class RougailTemplate:
chdir(self.templates_dir)
for option in await self.config.option.list(type='all'):
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,
is_variable_namespace,
is_var_namespace,
)
for template in listdir('.'):
self.prepare_template(template)
@ -396,6 +396,7 @@ class RougailTemplate:
variables[await option.option.name()] = subfamilies
else:
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()
return RougailExtra(variables)

View File

@ -72,7 +72,7 @@ class TiramisuReflector:
])
self.objectspace = objectspace
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")
def make_tiramisu_objects(self) -> None:
@ -95,8 +95,9 @@ class TiramisuReflector:
because `extra` family could use `variable_namespace` variables.
"""
if hasattr(self.objectspace.space, 'variables'):
if self.objectspace.rougailconfig['variable_namespace'] in self.objectspace.space.variables:
yield self.objectspace.space.variables[self.objectspace.rougailconfig['variable_namespace']]
variable_namespace = 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():
if elt != self.objectspace.rougailconfig['variable_namespace']:
yield value

View File

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

View File

@ -13,7 +13,7 @@ except:
from tiramisu import *
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_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_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])