support family in family
This commit is contained in:
@ -33,11 +33,12 @@ from ..config import Config
|
||||
|
||||
from .target import TargetAnnotator
|
||||
from .param import ParamAnnotator
|
||||
from .variable import Walk
|
||||
|
||||
FREEZE_AUTOFREEZE_VARIABLE = 'module_instancie'
|
||||
|
||||
|
||||
class ConditionAnnotator(TargetAnnotator, ParamAnnotator):
|
||||
class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
|
||||
"""Annotate condition
|
||||
"""
|
||||
def __init__(self,
|
||||
@ -66,16 +67,8 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator):
|
||||
"""convert auto_freeze
|
||||
only if FREEZE_AUTOFREEZE_VARIABLE == 'oui' this variable is frozen
|
||||
"""
|
||||
for variables in self.objectspace.space.variables.values():
|
||||
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:
|
||||
self._convert_auto_freeze(follower)
|
||||
else:
|
||||
self._convert_auto_freeze(variable)
|
||||
for variable in self.get_variables():
|
||||
self._convert_auto_freeze(variable)
|
||||
|
||||
def _convert_auto_freeze(self,
|
||||
variable: 'self.objectspace.variable',
|
||||
|
@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
from ..i18n import _
|
||||
from ..error import DictConsistencyError
|
||||
from ..utils import normalize_family
|
||||
from .variable import Walk
|
||||
|
||||
|
||||
#mode order is important
|
||||
@ -52,7 +53,7 @@ class Mode: # pylint: disable=R0903
|
||||
modes = {name: Mode(name, idx) for idx, name in enumerate(modes_level)}
|
||||
|
||||
|
||||
class FamilyAnnotator:
|
||||
class FamilyAnnotator(Walk):
|
||||
"""Annotate family
|
||||
"""
|
||||
def __init__(self,
|
||||
@ -67,50 +68,86 @@ class FamilyAnnotator:
|
||||
self.dynamic_families()
|
||||
self.convert_help()
|
||||
|
||||
def _has_variable(self,
|
||||
family: 'self.objectspace.family',
|
||||
) -> bool:
|
||||
if hasattr(family, 'variable'):
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
if self._has_variable(variable):
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
|
||||
def remove_empty_families(self) -> None:
|
||||
"""Remove all families without any variable
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
removed_families = []
|
||||
for family_name, family in families.family.items():
|
||||
if not hasattr(family, 'variable') or len(family.variable) == 0:
|
||||
for family_name, family in families.variable.items():
|
||||
if isinstance(family, self.objectspace.family) and not self._has_variable(family):
|
||||
removed_families.append(family_name)
|
||||
for family_name in removed_families:
|
||||
del families.family[family_name]
|
||||
del families.variable[family_name]
|
||||
|
||||
def family_names(self) -> None:
|
||||
"""Set doc, path, ... to family
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
families.doc = families.name
|
||||
families.path = families.name
|
||||
for family in families.family.values():
|
||||
if not hasattr(family, 'description'):
|
||||
family.description = family.name
|
||||
family.doc = family.description
|
||||
del family.description
|
||||
family.name = normalize_family(family.name)
|
||||
for family in self.get_families():
|
||||
if not hasattr(family, 'description'):
|
||||
family.description = family.name
|
||||
if not hasattr(family, 'path'):
|
||||
family.path = family.name
|
||||
family.doc = family.description
|
||||
del family.description
|
||||
family.name = normalize_family(family.name)
|
||||
|
||||
def change_modes(self):
|
||||
"""change the mode of variables
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.family.values():
|
||||
family_mode = family.mode
|
||||
# default is high level
|
||||
new_family_mode = modes_level[-1]
|
||||
for variable in family.variable.values():
|
||||
if not isinstance(variable, self.objectspace.leadership):
|
||||
func = self._change_variabe_mode
|
||||
else:
|
||||
func = self._change_variable_mode_leader
|
||||
func(variable,
|
||||
family_mode,
|
||||
)
|
||||
if modes[new_family_mode] > modes[variable.mode]:
|
||||
new_family_mode = variable.mode
|
||||
# set the lower variable mode to family
|
||||
family.mode = new_family_mode
|
||||
# default is high level
|
||||
new_family_mode = modes_level[-1]
|
||||
for family in self.objectspace.space.variables.values():
|
||||
self.change_family_mode(family,
|
||||
new_family_mode,
|
||||
first=True,
|
||||
)
|
||||
|
||||
def change_family_mode(self,
|
||||
family: 'self.objectspace.family',
|
||||
new_family_mode: str,
|
||||
first: bool=False,
|
||||
) -> str:
|
||||
if hasattr(family, 'mode'):
|
||||
family_mode = family.mode
|
||||
else:
|
||||
family_mode = new_family_mode
|
||||
if hasattr(family, 'variable'):
|
||||
# change variable mode, but not if variables are not in a family
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
new_family_mode = self.change_family_mode(variable,
|
||||
new_family_mode,
|
||||
)
|
||||
continue
|
||||
if first:
|
||||
continue
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
func = self._change_variable_mode_leader
|
||||
else:
|
||||
func = self._change_variabe_mode
|
||||
func(variable,
|
||||
family_mode,
|
||||
)
|
||||
if modes[new_family_mode] > modes[variable.mode]:
|
||||
new_family_mode = variable.mode
|
||||
if not first:
|
||||
# set the lower variable mode to family
|
||||
family.mode = new_family_mode
|
||||
return new_family_mode
|
||||
|
||||
def _change_variabe_mode(self,
|
||||
variable,
|
||||
@ -160,25 +197,27 @@ class FamilyAnnotator:
|
||||
def dynamic_families(self):
|
||||
"""link dynamic families to object
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.family.values():
|
||||
if 'dynamic' not in vars(family):
|
||||
continue
|
||||
family.suffixes = self.objectspace.paths.get_variable(family.dynamic)
|
||||
del family.dynamic
|
||||
if not family.suffixes.multi:
|
||||
msg = _(f'dynamic family "{family.name}" must be linked '
|
||||
f'to multi variable')
|
||||
raise DictConsistencyError(msg, 16, family.xmlfiles)
|
||||
for family in self.get_families():
|
||||
if 'dynamic' not in vars(family):
|
||||
continue
|
||||
family.suffixes = self.objectspace.paths.get_variable(family.dynamic)
|
||||
del family.dynamic
|
||||
if not family.suffixes.multi:
|
||||
msg = _(f'dynamic family "{family.name}" must be linked '
|
||||
f'to multi variable')
|
||||
raise DictConsistencyError(msg, 16, family.xmlfiles)
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
msg = _(f'dynamic family "{family.name}" cannot contains another family')
|
||||
raise DictConsistencyError(msg, 2, family.xmlfiles)
|
||||
|
||||
def convert_help(self):
|
||||
"""Convert variable help
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.family.values():
|
||||
if not hasattr(family, 'help'):
|
||||
continue
|
||||
if not hasattr(family, 'information'):
|
||||
family.information = self.objectspace.information(family.xmlfiles)
|
||||
family.information.help = family.help
|
||||
del family.help
|
||||
for family in self.get_families():
|
||||
if not hasattr(family, 'help'):
|
||||
continue
|
||||
if not hasattr(family, 'information'):
|
||||
family.information = self.objectspace.information(family.xmlfiles)
|
||||
family.information.help = family.help
|
||||
del family.help
|
||||
|
@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from ..i18n import _
|
||||
from ..error import DictConsistencyError
|
||||
from .variable import Walk
|
||||
|
||||
|
||||
PROPERTIES = ('hidden', 'frozen', 'auto_freeze', 'auto_save', 'force_default_on_freeze',
|
||||
@ -35,7 +36,7 @@ CONVERT_PROPERTIES = {'auto_save': ['force_store_value'],
|
||||
}
|
||||
|
||||
|
||||
class PropertyAnnotator:
|
||||
class PropertyAnnotator(Walk):
|
||||
"""Annotate properties
|
||||
"""
|
||||
def __init__(self, objectspace):
|
||||
@ -43,7 +44,8 @@ class PropertyAnnotator:
|
||||
if hasattr(self.objectspace.space, 'services'):
|
||||
self.convert_services()
|
||||
if hasattr(self.objectspace.space, 'variables'):
|
||||
self.convert_variables()
|
||||
self.convert_family()
|
||||
self.convert_variable()
|
||||
|
||||
def convert_property(self,
|
||||
variable,
|
||||
@ -92,15 +94,15 @@ class PropertyAnnotator:
|
||||
for variable in family.variable:
|
||||
self.convert_property(variable)
|
||||
|
||||
def convert_variables(self) -> None:
|
||||
def convert_family(self) -> None:
|
||||
"""convert variables
|
||||
"""
|
||||
for variables in self.objectspace.space.variables.values():
|
||||
for family in variables.family.values():
|
||||
self.convert_property(family)
|
||||
for variable in family.variable.values():
|
||||
self.convert_property(variable)
|
||||
if not isinstance(variable, self.objectspace.leadership):
|
||||
continue
|
||||
for follower in variable.variable:
|
||||
self.convert_property(follower)
|
||||
for family in self.get_families():
|
||||
self.convert_property(family)
|
||||
|
||||
def convert_variable(self) -> None:
|
||||
for variable in self.get_variables(with_leadership=True):
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
for follower in variable.variable:
|
||||
self.convert_property(follower)
|
||||
self.convert_property(variable)
|
||||
|
@ -35,7 +35,7 @@ from ..error import DictConsistencyError
|
||||
ERASED_ATTRIBUTES = ('redefine', 'exists', 'fallback', 'optional', 'remove_check', 'namespace',
|
||||
'remove_condition', 'path', 'instance_mode', 'index',
|
||||
'level', 'remove_fill', 'xmlfiles', 'type', 'reflector_name',
|
||||
'reflector_object', 'manage')
|
||||
'reflector_object',)
|
||||
|
||||
|
||||
KEY_TYPE = {'variable': 'symlink',
|
||||
@ -76,8 +76,6 @@ class ServiceAnnotator:
|
||||
self.objectspace.space.services.path = 'services'
|
||||
for service_name, service in self.objectspace.space.services.service.items():
|
||||
service.information = self.objectspace.information(service.xmlfiles)
|
||||
service.information.manage = service.manage
|
||||
service.manage = None
|
||||
for elttype, values in dict(vars(service)).items():
|
||||
if not isinstance(values, (dict, list)) or elttype in ERASED_ATTRIBUTES:
|
||||
continue
|
||||
|
@ -24,8 +24,9 @@ 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 .variable import Walk
|
||||
|
||||
class ValueAnnotator: # pylint: disable=R0903
|
||||
class ValueAnnotator(Walk): # pylint: disable=R0903
|
||||
"""Annotate value
|
||||
"""
|
||||
def __init__(self,
|
||||
@ -39,20 +40,16 @@ class ValueAnnotator: # pylint: disable=R0903
|
||||
def convert_value(self) -> None:
|
||||
"""convert value
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.family.values():
|
||||
if not hasattr(family, 'variable'):
|
||||
continue
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
variable_type = 'leader'
|
||||
for follower in variable.variable:
|
||||
self._convert_value(follower,
|
||||
variable_type,
|
||||
)
|
||||
variable_type = 'follower'
|
||||
else:
|
||||
self._convert_value(variable)
|
||||
for variable in self.get_variables(with_leadership=True):
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
variable_type = 'leader'
|
||||
for follower in variable.variable:
|
||||
self._convert_value(follower,
|
||||
variable_type,
|
||||
)
|
||||
variable_type = 'follower'
|
||||
else:
|
||||
self._convert_value(variable)
|
||||
|
||||
def _convert_value(self,
|
||||
variable,
|
||||
|
@ -63,7 +63,52 @@ FORCE_CHOICE = {'schedule': ['none', 'daily', 'weekly', 'monthly'],
|
||||
}
|
||||
|
||||
|
||||
class VariableAnnotator: # pylint: disable=R0903
|
||||
class Walk:
|
||||
"""Walk to objectspace to find variable or family
|
||||
"""
|
||||
def get_variables(self,
|
||||
with_leadership: bool=False,
|
||||
):
|
||||
"""Iter all variables from the objectspace
|
||||
"""
|
||||
for family in self.objectspace.space.variables.values():
|
||||
yield from self._get_variables(family, with_leadership)
|
||||
|
||||
def _get_variables(self,
|
||||
family: 'self.objectspace.family',
|
||||
with_leadership: bool
|
||||
):
|
||||
if hasattr(family, 'variable'):
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.family):
|
||||
yield from self._get_variables(variable, with_leadership)
|
||||
continue
|
||||
if not with_leadership and isinstance(variable, self.objectspace.leadership):
|
||||
for follower in variable.variable:
|
||||
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
|
||||
"""
|
||||
for family in self.objectspace.space.variables.values():
|
||||
yield from self._get_families(family)
|
||||
|
||||
def _get_families(self,
|
||||
family: 'self.objectspace.family',
|
||||
):
|
||||
yield family
|
||||
if hasattr(family, 'variable'):
|
||||
for fam in family.variable.values():
|
||||
if isinstance(fam, self.objectspace.family):
|
||||
yield from self._get_families(fam)
|
||||
|
||||
|
||||
class VariableAnnotator(Walk): # pylint: disable=R0903
|
||||
"""Annotate variable
|
||||
"""
|
||||
def __init__(self,
|
||||
@ -79,28 +124,21 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||
def convert_variable(self):
|
||||
"""convert variable
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.family.values():
|
||||
if not hasattr(family, 'variable'):
|
||||
continue
|
||||
for variable in family.variable.values():
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
# first variable is a leader, others are follower
|
||||
variable_type = 'leader'
|
||||
for follower in variable.variable:
|
||||
self._convert_variable(families.name,
|
||||
follower,
|
||||
variable_type,
|
||||
)
|
||||
variable_type = 'follower'
|
||||
else:
|
||||
self._convert_variable(families.name,
|
||||
variable,
|
||||
'variable',
|
||||
)
|
||||
for variable in self.get_variables(with_leadership=True):
|
||||
if isinstance(variable, self.objectspace.leadership):
|
||||
# first variable is a leader, others are follower
|
||||
variable_type = 'leader'
|
||||
for follower in variable.variable:
|
||||
self._convert_variable(follower,
|
||||
variable_type,
|
||||
)
|
||||
variable_type = 'follower'
|
||||
else:
|
||||
self._convert_variable(variable,
|
||||
'variable',
|
||||
)
|
||||
|
||||
def _convert_variable(self,
|
||||
namespace: str,
|
||||
variable,
|
||||
variable_type: str,
|
||||
) -> None:
|
||||
@ -127,12 +165,9 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||
variable.multi = 'submulti'
|
||||
else:
|
||||
variable.multi = True
|
||||
self._convert_valid_enum(namespace,
|
||||
variable,
|
||||
)
|
||||
self._convert_valid_enum(variable)
|
||||
|
||||
def _convert_valid_enum(self,
|
||||
namespace,
|
||||
variable,
|
||||
):
|
||||
"""some types are, in fact, choices
|
||||
@ -142,7 +177,7 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||
if not hasattr(self.objectspace.space, 'constraints'):
|
||||
xmlfiles = variable.xmlfiles
|
||||
self.objectspace.space.constraints = self.objectspace.constraints(xmlfiles)
|
||||
self.objectspace.space.constraints.namespace = namespace
|
||||
self.objectspace.space.constraints.namespace = variable.namespace
|
||||
if not hasattr(self.objectspace.space.constraints, 'check'):
|
||||
self.objectspace.space.constraints.check = []
|
||||
check = self.objectspace.check(variable.xmlfiles)
|
||||
@ -150,7 +185,7 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||
target = self.objectspace.target(variable.xmlfiles)
|
||||
target.name = variable.path
|
||||
check.target = [target]
|
||||
check.namespace = namespace
|
||||
check.namespace = variable.namespace
|
||||
check.param = []
|
||||
for value in FORCE_CHOICE[variable.type]:
|
||||
param = self.objectspace.param(variable.xmlfiles)
|
||||
@ -162,16 +197,8 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||
def convert_test(self):
|
||||
"""Convert variable tests value
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.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:
|
||||
self._convert_test(follower)
|
||||
else:
|
||||
self._convert_test(variable)
|
||||
for variable in self.get_variables():
|
||||
self._convert_test(variable)
|
||||
|
||||
def _convert_test(self,
|
||||
variable,
|
||||
@ -194,16 +221,8 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||
def convert_help(self):
|
||||
"""Convert variable help
|
||||
"""
|
||||
for families in self.objectspace.space.variables.values():
|
||||
for family in families.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:
|
||||
self._convert_help(follower)
|
||||
else:
|
||||
self._convert_help(variable)
|
||||
for variable in self.get_variables():
|
||||
self._convert_help(variable)
|
||||
|
||||
@staticmethod
|
||||
def _convert_help(variable) -> None:
|
||||
|
@ -37,7 +37,7 @@
|
||||
<!-- root element -->
|
||||
<!-- =============== -->
|
||||
|
||||
<!ELEMENT rougail (services | variables | constraints | help)*>
|
||||
<!ELEMENT rougail (services|variables|constraints|help)*>
|
||||
|
||||
<!-- ============== -->
|
||||
<!-- files element -->
|
||||
@ -45,17 +45,16 @@
|
||||
|
||||
<!ELEMENT services (service*)>
|
||||
|
||||
<!ELEMENT service ((port* | ip* | file* | override*)*) >
|
||||
<!ELEMENT service ((port*|ip*|file*|override*)*)>
|
||||
<!ATTLIST service name CDATA #REQUIRED>
|
||||
<!ATTLIST service manage (True|False) "True">
|
||||
|
||||
<!ELEMENT port (#PCDATA)>
|
||||
<!ATTLIST port port_type (PortOption|variable) "PortOption">
|
||||
<!ATTLIST port portlist CDATA #IMPLIED >
|
||||
<!ATTLIST port portlist CDATA #IMPLIED>
|
||||
<!ATTLIST port protocol (tcp|udp) "tcp">
|
||||
|
||||
<!ELEMENT ip (#PCDATA)>
|
||||
<!ATTLIST ip iplist CDATA #IMPLIED >
|
||||
<!ATTLIST ip iplist CDATA #IMPLIED>
|
||||
<!ATTLIST ip ip_type (NetworkOption|variable) "NetworkOption">
|
||||
<!ATTLIST ip interface_type (UnicodeOption|variable) "UnicodeOption">
|
||||
<!ATTLIST ip interface CDATA #REQUIRED>
|
||||
@ -63,7 +62,7 @@
|
||||
<!ATTLIST ip netmask CDATA "255.255.255.255">
|
||||
|
||||
<!ELEMENT file EMPTY>
|
||||
<!ATTLIST file name CDATA #REQUIRED >
|
||||
<!ATTLIST file name CDATA #REQUIRED>
|
||||
<!ATTLIST file file_type (UnicodeOption|variable) "UnicodeOption">
|
||||
<!ATTLIST file variable CDATA #IMPLIED>
|
||||
<!ATTLIST file variable_type (variable) "variable">
|
||||
@ -71,17 +70,17 @@
|
||||
<!ATTLIST file mode CDATA "0644">
|
||||
<!ATTLIST file owner CDATA "root">
|
||||
<!ATTLIST file group CDATA "root">
|
||||
<!ATTLIST file filelist CDATA #IMPLIED >
|
||||
<!ATTLIST file filelist CDATA #IMPLIED>
|
||||
<!ATTLIST file redefine (True|False) "False">
|
||||
<!ATTLIST file templating (True|False) "True">
|
||||
|
||||
<!ELEMENT override EMPTY>
|
||||
<!ATTLIST override source CDATA #IMPLIED >
|
||||
<!ATTLIST override source CDATA #IMPLIED>
|
||||
<!ATTLIST override templating (True|False) "True">
|
||||
|
||||
<!ELEMENT variables (family*)>
|
||||
<!ELEMENT variables ((variable*|family*)*)>
|
||||
|
||||
<!ELEMENT family (variable*)>
|
||||
<!ELEMENT family ((variable*|family*)*)>
|
||||
<!ATTLIST family name CDATA #REQUIRED>
|
||||
<!ATTLIST family description CDATA #IMPLIED>
|
||||
<!ATTLIST family help CDATA #IMPLIED>
|
||||
@ -110,7 +109,7 @@
|
||||
|
||||
<!ELEMENT value (#PCDATA)>
|
||||
|
||||
<!ELEMENT constraints ((fill* | check* | condition* | group*)*)>
|
||||
<!ELEMENT constraints ((fill*|check*|condition*|group*)*)>
|
||||
|
||||
<!ELEMENT fill ((target|param)+)>
|
||||
<!ATTLIST fill name CDATA #REQUIRED>
|
||||
@ -127,7 +126,7 @@
|
||||
<!ATTLIST condition force_inverse_condition_on_fallback (True|False) "False">
|
||||
|
||||
<!ELEMENT param (#PCDATA)>
|
||||
<!ATTLIST param type (string|number|nil|variable|information|suffix) "string">
|
||||
<!ATTLIST param type (string|number|nil|boolean|variable|information|suffix) "string">
|
||||
<!ATTLIST param name CDATA #IMPLIED>
|
||||
<!ATTLIST param propertyerror (True|False) "True">
|
||||
<!ATTLIST param optional (True|False) "False">
|
||||
|
@ -43,7 +43,9 @@ UNREDEFINABLE = ('multi', 'type')
|
||||
# RougailObjSpace's elements that did not created automaticly
|
||||
FORCE_ELEMENTS = ('choice', 'property_', 'leadership', 'information')
|
||||
# XML text are convert has name
|
||||
FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value', 'target')
|
||||
FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value',)
|
||||
|
||||
FORCE_TAG = {'family': 'variable'}
|
||||
|
||||
|
||||
# _____________________________________________________________________________
|
||||
@ -236,7 +238,8 @@ class RougailObjSpace:
|
||||
"""
|
||||
retrieves or creates Rougail Object Subspace objects
|
||||
"""
|
||||
obj = getattr(self, child.tag)
|
||||
tag = FORCE_TAG.get(child.tag, child.tag)
|
||||
obj = getattr(self, tag)
|
||||
name = self._get_name(child, namespace)
|
||||
if Redefinable in obj.__mro__:
|
||||
return self.create_or_update_redefinable_object(xmlfile,
|
||||
@ -314,8 +317,9 @@ class RougailObjSpace:
|
||||
# cannot redefine an inexistant object
|
||||
msg = _(f'Redefined object: "{name}" does not exist yet')
|
||||
raise DictConsistencyError(msg, 46, xmlfile)
|
||||
if child.tag not in vars(space):
|
||||
setattr(space, child.tag, {})
|
||||
tag = FORCE_TAG.get(child.tag, child.tag)
|
||||
if tag not in vars(space):
|
||||
setattr(space, tag, {})
|
||||
return getattr(self, child.tag)(xmlfile, name)
|
||||
|
||||
def get_existed_obj(self,
|
||||
@ -328,7 +332,7 @@ class RougailObjSpace:
|
||||
"""
|
||||
if child.tag in ['variable', 'family']:
|
||||
name = normalize_family(name)
|
||||
if isinstance(space, self.family): # pylint: disable=E1101
|
||||
if child.tag == 'variable': # pylint: disable=E1101
|
||||
if namespace != Config['variable_namespace']:
|
||||
name = space.path + '.' + name
|
||||
if not self.paths.path_is_defined(name):
|
||||
@ -340,7 +344,8 @@ class RougailObjSpace:
|
||||
raise DictConsistencyError(msg, 47, space.xmlfiles)
|
||||
return self.paths.get_variable(name)
|
||||
# it's not a family
|
||||
children = getattr(space, child.tag, {})
|
||||
tag = FORCE_TAG.get(child.tag, child.tag)
|
||||
children = getattr(space, tag, {})
|
||||
if name in children:
|
||||
return children[name]
|
||||
return None
|
||||
@ -458,7 +463,10 @@ class RougailObjSpace:
|
||||
"""Fill self.paths attributes
|
||||
"""
|
||||
if isinstance(variableobj, self.variable): # pylint: disable=E1101
|
||||
family_name = normalize_family(document.attrib['name'])
|
||||
if 'name' in document.attrib:
|
||||
family_name = normalize_family(document.attrib['name'])
|
||||
else:
|
||||
family_name = namespace
|
||||
self.paths.add_variable(namespace,
|
||||
normalize_family(variableobj.name),
|
||||
namespace + '.' + family_name,
|
||||
@ -485,9 +493,10 @@ class RougailObjSpace:
|
||||
variableobj.namespace = namespace
|
||||
if isinstance(variableobj, Redefinable):
|
||||
name = variableobj.name
|
||||
tag = FORCE_TAG.get(child.tag, child.tag)
|
||||
if child.tag in ['family', 'variable']:
|
||||
name = normalize_family(name)
|
||||
getattr(space, child.tag)[name] = variableobj
|
||||
getattr(space, tag)[name] = variableobj
|
||||
elif isinstance(variableobj, UnRedefinable):
|
||||
getattr(space, child.tag).append(variableobj)
|
||||
else:
|
||||
|
@ -62,11 +62,11 @@ class XMLReflector:
|
||||
try:
|
||||
document = parse(xmlfile)
|
||||
except XMLSyntaxError as err:
|
||||
raise DictConsistencyError(_(f'not an XML file: {err}'), 52, xmlfile) from err
|
||||
raise DictConsistencyError(_(f'not a XML file: {err}'), 52, [xmlfile]) from err
|
||||
if not self.dtd.validate(document):
|
||||
dtd_error = self.dtd.error_log.filter_from_errors()[0]
|
||||
msg = _(f'not a valid XML file: {dtd_error}')
|
||||
raise DictConsistencyError(msg, 43, xmlfile)
|
||||
raise DictConsistencyError(msg, 43, [xmlfile])
|
||||
return document.getroot()
|
||||
|
||||
@staticmethod
|
||||
|
Reference in New Issue
Block a user