remove oui/non yes/no ... types
This commit is contained in:
@ -44,15 +44,15 @@ class ConstrainteAnnotator:
|
||||
objectspace,
|
||||
eosfunc_file,
|
||||
):
|
||||
if not hasattr(objectspace.space, 'constraints'):
|
||||
return
|
||||
self.objectspace = objectspace
|
||||
eosfunc = SourceFileLoader('eosfunc', eosfunc_file).load_module()
|
||||
self.functions = dir(eosfunc)
|
||||
self.functions.extend(INTERNAL_FUNCTIONS)
|
||||
self.valid_enums = {}
|
||||
|
||||
self.convert_auto_freeze()
|
||||
if hasattr(objectspace.space, 'variables'):
|
||||
self.convert_auto_freeze()
|
||||
if not hasattr(objectspace.space, 'constraints'):
|
||||
return
|
||||
if hasattr(self.objectspace.space.constraints, 'check'):
|
||||
self.check_check()
|
||||
self.check_valid_enum()
|
||||
@ -73,15 +73,15 @@ class ConstrainteAnnotator:
|
||||
"""convert auto_freeze
|
||||
only if FREEZE_AUTOFREEZE_VARIABLE == 'oui' this variable is frozen
|
||||
"""
|
||||
def _convert_auto_freeze(variable, namespace):
|
||||
def _convert_auto_freeze(variable):
|
||||
if variable.auto_freeze:
|
||||
if namespace != Config['variable_namespace']:
|
||||
if variable.namespace != Config['variable_namespace']:
|
||||
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||
msg = _(f'auto_freeze is not allowed in extra "{namespace}" in {xmlfiles}')
|
||||
msg = _(f'auto_freeze is not allowed in extra "{variable.namespace}" in {xmlfiles}')
|
||||
raise DictConsistencyError(msg, 49)
|
||||
new_condition = self.objectspace.condition(variable.xmlfiles)
|
||||
new_condition.name = 'auto_frozen_if_not_in'
|
||||
new_condition.namespace = namespace
|
||||
new_condition.namespace = variable.namespace
|
||||
new_condition.source = FREEZE_AUTOFREEZE_VARIABLE
|
||||
new_param = self.objectspace.param(variable.xmlfiles)
|
||||
new_param.text = 'oui'
|
||||
@ -90,25 +90,21 @@ class ConstrainteAnnotator:
|
||||
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)
|
||||
for variables in self.objectspace.space.variables.values():
|
||||
if not hasattr(variables, 'family'):
|
||||
continue
|
||||
for family in variables.family.values():
|
||||
if not hasattr(family, 'variable'):
|
||||
continue
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
for follower in variable.variable:
|
||||
_convert_auto_freeze(follower,
|
||||
variables.namespace,
|
||||
)
|
||||
_convert_auto_freeze(follower)
|
||||
else:
|
||||
_convert_auto_freeze(variable,
|
||||
variables.namespace,
|
||||
)
|
||||
_convert_auto_freeze(variable)
|
||||
|
||||
def check_check(self):
|
||||
"""valid and manage <check>
|
||||
|
@ -54,13 +54,8 @@ class PropertyAnnotator:
|
||||
if not isinstance(service, self.objectspace.family):
|
||||
continue
|
||||
self.convert_property(service)
|
||||
if not hasattr(service, 'family'):
|
||||
continue
|
||||
self.convert_property(service)
|
||||
for family in service.family:
|
||||
self.convert_property(family)
|
||||
if not hasattr(family, 'variable'):
|
||||
continue
|
||||
for variable in family.variable:
|
||||
self.convert_property(variable)
|
||||
|
||||
@ -68,16 +63,11 @@ class PropertyAnnotator:
|
||||
"""convert variables
|
||||
"""
|
||||
for variables in self.objectspace.space.variables.values():
|
||||
if not hasattr(variables, 'family'):
|
||||
continue
|
||||
for family in variables.family.values():
|
||||
self.convert_property(family)
|
||||
if not hasattr(family, 'variable'):
|
||||
continue
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
self.convert_property(variable)
|
||||
for follower in variable.variable:
|
||||
self.convert_property(follower)
|
||||
else:
|
||||
self.convert_property(variable)
|
||||
self.convert_property(variable)
|
||||
if not isinstance(variable, self.objectspace.leadership):
|
||||
continue
|
||||
for follower in variable.variable:
|
||||
self.convert_property(follower)
|
||||
|
@ -7,7 +7,7 @@ from ..error import DictConsistencyError
|
||||
# that shall not be present in the exported (flatened) XML
|
||||
ERASED_ATTRIBUTES = ('redefine', 'exists', 'fallback', 'optional', 'remove_check', 'namespace',
|
||||
'remove_condition', 'path', 'instance_mode', 'index', 'is_in_leadership',
|
||||
'level', 'remove_fill', 'xmlfiles')
|
||||
'level', 'remove_fill', 'xmlfiles', 'type')
|
||||
|
||||
|
||||
KEY_TYPE = {'variable': 'symlink',
|
||||
|
@ -37,11 +37,9 @@ CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
|
||||
}
|
||||
|
||||
|
||||
FORCE_CHOICE = {'oui/non': ['oui', 'non'],
|
||||
'on/off': ['on', 'off'],
|
||||
'yes/no': ['yes', 'no'],
|
||||
'schedule': ['none', 'daily', 'weekly', 'monthly'],
|
||||
'schedulemod': ['pre', 'post']}
|
||||
FORCE_CHOICE = {'schedule': ['none', 'daily', 'weekly', 'monthly'],
|
||||
'schedulemod': ['pre', 'post'],
|
||||
}
|
||||
|
||||
|
||||
RENAME_ATTIBUTES = {'description': 'doc'}
|
||||
@ -63,8 +61,6 @@ class VariableAnnotator:
|
||||
variable,
|
||||
variable_type: str,
|
||||
) -> None:
|
||||
if not hasattr(variable, 'type'):
|
||||
variable.type = 'string'
|
||||
if variable.type != 'symlink' and not hasattr(variable, 'description'):
|
||||
variable.description = variable.name
|
||||
if hasattr(variable, 'value'):
|
||||
@ -83,7 +79,6 @@ class VariableAnnotator:
|
||||
self._convert_valid_enum(namespace,
|
||||
variable,
|
||||
)
|
||||
self._valid_type(variable)
|
||||
|
||||
def _convert_valid_enum(self,
|
||||
namespace,
|
||||
@ -111,20 +106,10 @@ class VariableAnnotator:
|
||||
self.objectspace.space.constraints.check.append(check)
|
||||
variable.type = 'string'
|
||||
|
||||
def _valid_type(self,
|
||||
variable
|
||||
) -> None:
|
||||
if variable.type not in CONVERT_OPTION:
|
||||
xmlf = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||
msg = _(f'unvalid type "{variable.type}" for variable "{variable.name}" in {xmlf}')
|
||||
raise DictConsistencyError(msg, 36)
|
||||
|
||||
def convert_variable(self):
|
||||
"""convert variable
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
if not hasattr(families, 'family'):
|
||||
continue
|
||||
families.doc = families.name
|
||||
for family in families.family.values():
|
||||
family.doc = family.name
|
||||
|
@ -90,7 +90,7 @@
|
||||
|
||||
<!ELEMENT variable (value*)>
|
||||
<!ATTLIST variable name CDATA #REQUIRED>
|
||||
<!ATTLIST variable type CDATA #IMPLIED>
|
||||
<!ATTLIST variable type (number|float|string|password|mail|boolean|filename|date|unix_user|ip|local_ip|netmask|network|broadcast|netbios|domain|hostname|web_address|port|mac|cidr|network_cidr|schedule|schedulemod) "string">
|
||||
<!ATTLIST variable description CDATA #IMPLIED>
|
||||
<!ATTLIST variable help CDATA #IMPLIED>
|
||||
<!ATTLIST variable hidden (True|False) "False">
|
||||
|
@ -266,7 +266,6 @@ class Variable(Common):
|
||||
)
|
||||
self.is_follower = is_follower
|
||||
convert_option = CONVERT_OPTION[elt.type]
|
||||
del elt.type
|
||||
self.object_type = convert_option['opttype']
|
||||
self.attrib.update(convert_option.get('initkwargs', {}))
|
||||
if self.object_type != 'SymLinkOption':
|
||||
|
Reference in New Issue
Block a user