target in check is not an object
This commit is contained in:
parent
712175d56b
commit
1d0a5fae18
|
@ -116,6 +116,17 @@ class ConstrainteAnnotator:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
msg = _(f'cannot find check function "{check.name}" in {xmlfiles}')
|
msg = _(f'cannot find check function "{check.name}" in {xmlfiles}')
|
||||||
raise DictConsistencyError(msg, 1)
|
raise DictConsistencyError(msg, 1)
|
||||||
|
check.is_in_leadership = self.objectspace.paths.get_leader(check.target) is not None
|
||||||
|
# let's replace the target by the path
|
||||||
|
try:
|
||||||
|
check.target = self.objectspace.paths.get_variable_obj(check.target)
|
||||||
|
except DictConsistencyError as err:
|
||||||
|
if err.errno == 36:
|
||||||
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
|
msg = _(f'the target "{check.target}" in check cannot be a dynamic '
|
||||||
|
f'variable in {xmlfiles}')
|
||||||
|
raise DictConsistencyError(msg, 22)
|
||||||
|
raise err
|
||||||
if not hasattr(check, 'param'):
|
if not hasattr(check, 'param'):
|
||||||
continue
|
continue
|
||||||
param_option_indexes = []
|
param_option_indexes = []
|
||||||
|
@ -129,20 +140,19 @@ class ConstrainteAnnotator:
|
||||||
param_option_indexes.append(idx)
|
param_option_indexes.append(idx)
|
||||||
else:
|
else:
|
||||||
# let's replace params by the path
|
# let's replace params by the path
|
||||||
param.text = self.objectspace.paths.get_variable_path(param.text,
|
param.text, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||||||
check.namespace,
|
check.namespace,
|
||||||
)
|
)
|
||||||
|
if suffix:
|
||||||
|
xmlfiles = self.objectspace.display_xmlfiles(param.xmlfiles)
|
||||||
|
msg = _(f'the param "{param.text}" in check cannot be a dynamic '
|
||||||
|
f'variable in {xmlfiles}')
|
||||||
|
raise DictConsistencyError(msg, 23)
|
||||||
param_option_indexes.sort(reverse=True)
|
param_option_indexes.sort(reverse=True)
|
||||||
for idx in param_option_indexes:
|
for idx in param_option_indexes:
|
||||||
check.param.pop(idx)
|
check.param.pop(idx)
|
||||||
if check.param == []:
|
if check.param == []:
|
||||||
remove_indexes.append(check_idx)
|
remove_indexes.append(check_idx)
|
||||||
continue
|
|
||||||
# let's replace the target by the path
|
|
||||||
check.target = self.objectspace.paths.get_variable_path(check.target,
|
|
||||||
check.namespace,
|
|
||||||
)
|
|
||||||
check.is_in_leadership = self.objectspace.paths.get_leader(check.target) is not None
|
|
||||||
remove_indexes.sort(reverse=True)
|
remove_indexes.sort(reverse=True)
|
||||||
for idx in remove_indexes:
|
for idx in remove_indexes:
|
||||||
del self.objectspace.space.constraints.check[idx]
|
del self.objectspace.space.constraints.check[idx]
|
||||||
|
@ -152,34 +162,34 @@ class ConstrainteAnnotator:
|
||||||
"""
|
"""
|
||||||
remove_indexes = []
|
remove_indexes = []
|
||||||
for idx, check in enumerate(self.objectspace.space.constraints.check):
|
for idx, check in enumerate(self.objectspace.space.constraints.check):
|
||||||
if check.name == 'valid_enum':
|
if check.name != 'valid_enum':
|
||||||
if check.target in self.valid_enums:
|
continue
|
||||||
check_xmlfiles = self.valid_enums[check.target]['xmlfiles']
|
if check.target.path in self.valid_enums:
|
||||||
|
check_xmlfiles = self.valid_enums[check.target.path]['xmlfiles']
|
||||||
old_xmlfiles = self.objectspace.display_xmlfiles(check_xmlfiles)
|
old_xmlfiles = self.objectspace.display_xmlfiles(check_xmlfiles)
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
msg = _(f'valid_enum define in {xmlfiles} but already set in {old_xmlfiles} '
|
msg = _(f'valid_enum define in {xmlfiles} but already set in {old_xmlfiles} '
|
||||||
f'for "{check.target}", did you forget remove_check?')
|
f'for "{check.target.name}", did you forget remove_check?')
|
||||||
raise DictConsistencyError(msg, 3)
|
raise DictConsistencyError(msg, 3)
|
||||||
if not hasattr(check, 'param'):
|
if not hasattr(check, 'param'):
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
msg = _(f'param is mandatory for a valid_enum of variable "{check.target}" '
|
msg = _(f'param is mandatory for a valid_enum of variable "{check.target.name}" '
|
||||||
f'in {xmlfiles}')
|
f'in {xmlfiles}')
|
||||||
raise DictConsistencyError(msg, 4)
|
raise DictConsistencyError(msg, 4)
|
||||||
variable = self.objectspace.paths.get_variable_obj(check.target)
|
variable_type = check.target.type
|
||||||
variable_type = variable.type
|
values = self._set_valid_enum(check.target,
|
||||||
values = self._set_valid_enum(variable,
|
|
||||||
check,
|
check,
|
||||||
)
|
)
|
||||||
if values:
|
if values:
|
||||||
if hasattr(variable, 'value'):
|
if hasattr(check.target, 'value'):
|
||||||
# check value
|
# check value
|
||||||
check_valid_enum_value(variable, values)
|
check_valid_enum_value(check.target, values)
|
||||||
else:
|
else:
|
||||||
# no value, set the first choice has default value
|
# no value, set the first choice has default value
|
||||||
new_value = self.objectspace.value(check.xmlfiles)
|
new_value = self.objectspace.value(check.xmlfiles)
|
||||||
new_value.name = values[0]
|
new_value.name = values[0]
|
||||||
new_value.type = variable_type
|
new_value.type = variable_type
|
||||||
variable.value = [new_value]
|
check.target.value = [new_value]
|
||||||
remove_indexes.append(idx)
|
remove_indexes.append(idx)
|
||||||
remove_indexes.sort(reverse=True)
|
remove_indexes.sort(reverse=True)
|
||||||
for idx in remove_indexes:
|
for idx in remove_indexes:
|
||||||
|
@ -250,7 +260,7 @@ class ConstrainteAnnotator:
|
||||||
if has_variable:
|
if has_variable:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.valid_enums[check.target] = {'type': variable_type,
|
self.valid_enums[check.target.path] = {'type': variable_type,
|
||||||
'values': values,
|
'values': values,
|
||||||
'xmlfiles': check.xmlfiles,
|
'xmlfiles': check.xmlfiles,
|
||||||
}
|
}
|
||||||
|
@ -298,9 +308,14 @@ class ConstrainteAnnotator:
|
||||||
target_names = '.'.join([normalize_family(name) \
|
target_names = '.'.join([normalize_family(name) \
|
||||||
for name in target.name.split('.')])
|
for name in target.name.split('.')])
|
||||||
try:
|
try:
|
||||||
target.name = self.objectspace.paths.get_variable_path(target_names,
|
target.name, suffix = self.objectspace.paths.get_variable_path(target_names,
|
||||||
condition.namespace,
|
condition.namespace,
|
||||||
)
|
)
|
||||||
|
if suffix:
|
||||||
|
xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles)
|
||||||
|
msg = _(f'the target "{target.name}" in condition cannot be a dynamic '
|
||||||
|
f'variable in {xmlfiles}')
|
||||||
|
raise DictConsistencyError(msg, 21)
|
||||||
except DictConsistencyError as err:
|
except DictConsistencyError as err:
|
||||||
# for optional variable
|
# for optional variable
|
||||||
if not target.optional or err.errno != 42:
|
if not target.optional or err.errno != 42:
|
||||||
|
@ -402,7 +417,6 @@ class ConstrainteAnnotator:
|
||||||
condition.source, suffix = self.objectspace.paths.get_variable_path(condition.source,
|
condition.source, suffix = self.objectspace.paths.get_variable_path(condition.source,
|
||||||
namespace,
|
namespace,
|
||||||
allow_source=True,
|
allow_source=True,
|
||||||
with_suffix=True,
|
|
||||||
)
|
)
|
||||||
if suffix:
|
if suffix:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles)
|
||||||
|
@ -491,7 +505,6 @@ class ConstrainteAnnotator:
|
||||||
"""valid and manage <check>
|
"""valid and manage <check>
|
||||||
"""
|
"""
|
||||||
for check in self.objectspace.space.constraints.check:
|
for check in self.objectspace.space.constraints.check:
|
||||||
variable = self.objectspace.paths.get_variable_obj(check.target)
|
|
||||||
if check.name == 'valid_entier':
|
if check.name == 'valid_entier':
|
||||||
if not hasattr(check, 'param'):
|
if not hasattr(check, 'param'):
|
||||||
msg = _(f'{check.name} must have, at least, 1 param')
|
msg = _(f'{check.name} must have, at least, 1 param')
|
||||||
|
@ -503,18 +516,18 @@ class ConstrainteAnnotator:
|
||||||
f' in {xmlfiles}')
|
f' in {xmlfiles}')
|
||||||
raise DictConsistencyError(msg, 18)
|
raise DictConsistencyError(msg, 18)
|
||||||
if param.name == 'mini':
|
if param.name == 'mini':
|
||||||
variable.min_number = int(param.text)
|
check.target.min_number = int(param.text)
|
||||||
elif param.name == 'maxi':
|
elif param.name == 'maxi':
|
||||||
variable.max_number = int(param.text)
|
check.target.max_number = int(param.text)
|
||||||
else:
|
else:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(check.xmlfiles)
|
||||||
msg = _(f'unknown parameter "{param.name}" in check "valid_entier" '
|
msg = _(f'unknown parameter "{param.name}" in check "valid_entier" '
|
||||||
f'for variable "{check.target}" in {xmlfiles}')
|
f'for variable "{check.target.name}" in {xmlfiles}')
|
||||||
raise DictConsistencyError(msg, 19)
|
raise DictConsistencyError(msg, 19)
|
||||||
else:
|
else:
|
||||||
if not hasattr(variable, 'check'):
|
if not hasattr(check.target, 'check'):
|
||||||
variable.check = []
|
check.target.check = []
|
||||||
variable.check.append(check)
|
check.target.check.append(check)
|
||||||
|
|
||||||
def convert_fill(self) -> None:
|
def convert_fill(self) -> None:
|
||||||
"""valid and manage <fill>
|
"""valid and manage <fill>
|
||||||
|
@ -538,7 +551,6 @@ class ConstrainteAnnotator:
|
||||||
# let's replace the target by the path
|
# let's replace the target by the path
|
||||||
fill.target, suffix = self.objectspace.paths.get_variable_path(fill.target,
|
fill.target, suffix = self.objectspace.paths.get_variable_path(fill.target,
|
||||||
fill.namespace,
|
fill.namespace,
|
||||||
with_suffix=True,
|
|
||||||
)
|
)
|
||||||
if suffix is not None:
|
if suffix is not None:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(fill.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(fill.xmlfiles)
|
||||||
|
@ -591,7 +603,6 @@ class ConstrainteAnnotator:
|
||||||
try:
|
try:
|
||||||
text, suffix = self.objectspace.paths.get_variable_path(param.text,
|
text, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||||||
fill.namespace,
|
fill.namespace,
|
||||||
with_suffix=True,
|
|
||||||
)
|
)
|
||||||
param.text = text
|
param.text = text
|
||||||
if suffix:
|
if suffix:
|
||||||
|
|
|
@ -177,9 +177,13 @@ class ServiceAnnotator:
|
||||||
variable.mode = None
|
variable.mode = None
|
||||||
variable.type = type_
|
variable.type = type_
|
||||||
if type_ == 'symlink':
|
if type_ == 'symlink':
|
||||||
variable.opt = self.objectspace.paths.get_variable_path(value,
|
variable.opt, suffix = self.objectspace.paths.get_variable_path(value,
|
||||||
'services',
|
'services',
|
||||||
)
|
)
|
||||||
|
if suffix:
|
||||||
|
xmlfiles = self.objectspace.display_xmlfiles(value.xmlfiles)
|
||||||
|
msg = _(f'the "{key}" in services cannot be a dynamic variable in {xmlfiles}')
|
||||||
|
raise DictConsistencyError(msg, 23)
|
||||||
variable.multi = None
|
variable.multi = None
|
||||||
else:
|
else:
|
||||||
variable.doc = key
|
variable.doc = key
|
||||||
|
|
|
@ -16,11 +16,6 @@ class TemplateDisabled(TemplateError):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class OperationError(Exception):
|
|
||||||
"""Type error or value Error for Creole variable's type or values
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class SpaceObjShallNotBeUpdated(Exception):
|
class SpaceObjShallNotBeUpdated(Exception):
|
||||||
"""Specific behavior in case of the presence or not
|
"""Specific behavior in case of the presence or not
|
||||||
of an object in the space object
|
of an object in the space object
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .error import OperationError, DictConsistencyError
|
from .error import DictConsistencyError
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,7 +110,6 @@ class Path:
|
||||||
variableobj.path = full_path
|
variableobj.path = full_path
|
||||||
self.variables[full_path] = dict(name=name,
|
self.variables[full_path] = dict(name=name,
|
||||||
family=family,
|
family=family,
|
||||||
namespace=namespace,
|
|
||||||
leader=None,
|
leader=None,
|
||||||
is_dynamic=is_dynamic,
|
is_dynamic=is_dynamic,
|
||||||
variableobj=variableobj,
|
variableobj=variableobj,
|
||||||
|
@ -119,7 +118,10 @@ class Path:
|
||||||
def get_variable_obj(self,
|
def get_variable_obj(self,
|
||||||
name: str,
|
name: str,
|
||||||
) -> 'Variable': # pylint: disable=C0111
|
) -> 'Variable': # pylint: disable=C0111
|
||||||
return self._get_variable(name)['variableobj']
|
variable, suffix = self._get_variable(name, with_suffix=True)
|
||||||
|
if suffix:
|
||||||
|
raise DictConsistencyError(_("{name} is a dynamic variable"), 36)
|
||||||
|
return variable['variableobj']
|
||||||
|
|
||||||
def get_variable_family_name(self,
|
def get_variable_family_name(self,
|
||||||
name: str,
|
name: str,
|
||||||
|
@ -130,26 +132,14 @@ class Path:
|
||||||
name: str,
|
name: str,
|
||||||
current_namespace: str,
|
current_namespace: str,
|
||||||
allow_source: str=False,
|
allow_source: str=False,
|
||||||
with_suffix: bool=False,
|
|
||||||
) -> str: # pylint: disable=C0111
|
) -> str: # pylint: disable=C0111
|
||||||
if current_namespace is None: # pragma: no cover
|
|
||||||
raise OperationError('current_namespace must not be None')
|
|
||||||
if with_suffix:
|
|
||||||
dico, suffix = self._get_variable(name,
|
dico, suffix = self._get_variable(name,
|
||||||
with_suffix=True,
|
with_suffix=True,
|
||||||
)
|
)
|
||||||
else:
|
namespace = dico['variableobj'].namespace
|
||||||
dico = self._get_variable(name)
|
if not allow_source and namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace:
|
||||||
if not allow_source and dico['namespace'] not in [Config['variable_namespace'], 'services'] and current_namespace != dico['namespace']:
|
raise DictConsistencyError(_(f'A variable located in the "{namespace}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
|
||||||
raise DictConsistencyError(_(f'A variable located in the "{dico["namespace"]}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
|
return dico['variableobj'].path, suffix
|
||||||
list_path = [dico['namespace'], dico['family']]
|
|
||||||
if dico['leader'] is not None:
|
|
||||||
list_path.append(dico['leader'])
|
|
||||||
list_path.append(dico['name'])
|
|
||||||
value = '.'.join(list_path)
|
|
||||||
if with_suffix:
|
|
||||||
return value, suffix
|
|
||||||
return value
|
|
||||||
|
|
||||||
def path_is_defined(self,
|
def path_is_defined(self,
|
||||||
name: str,
|
name: str,
|
||||||
|
|
Loading…
Reference in New Issue