remove pylint comment
This commit is contained in:
parent
ca40aa5ec3
commit
fffd52eec6
|
@ -4,11 +4,6 @@ as an input and outputs a Tiramisu's file
|
||||||
|
|
||||||
Sample usage::
|
Sample usage::
|
||||||
|
|
||||||
eolobj.space_visitor(func)
|
|
||||||
xml = eolobj.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
>>> from rougail.objspace import RougailObjSpace
|
>>> from rougail.objspace import RougailObjSpace
|
||||||
>>> eolobj = RougailObjSpace('/usr/share/rougail/rougail.dtd')
|
>>> eolobj = RougailObjSpace('/usr/share/rougail/rougail.dtd')
|
||||||
>>> eolobj.create_or_populate_from_xml('rougail', ['/usr/share/rougail/dicos'])
|
>>> eolobj.create_or_populate_from_xml('rougail', ['/usr/share/rougail/dicos'])
|
||||||
|
@ -74,11 +69,10 @@ class ObjSpace:
|
||||||
|
|
||||||
|
|
||||||
class RougailObjSpace:
|
class RougailObjSpace:
|
||||||
"""DOM XML reflexion free internal representation of a Rougail Dictionary
|
"""Rougail ObjectSpace is an object's reflexion of the XML elements
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __init__(self, dtdfilename):
|
||||||
def __init__(self, dtdfilename): # pylint: disable=R0912
|
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.space = ObjSpace()
|
self.space = ObjSpace()
|
||||||
self.paths = Path()
|
self.paths = Path()
|
||||||
|
@ -91,13 +85,13 @@ class RougailObjSpace:
|
||||||
self.list_conditions = {}
|
self.list_conditions = {}
|
||||||
self.booleans_attributs = []
|
self.booleans_attributs = []
|
||||||
|
|
||||||
self.make_object_space_class()
|
self.make_object_space_classes()
|
||||||
|
|
||||||
def make_object_space_class(self):
|
def make_object_space_classes(self):
|
||||||
"""Create Rougail ObjectSpace class types, it enables us to create objects like:
|
"""Create Rougail ObjectSpace class types from DDT file
|
||||||
|
It enables us to create objects like:
|
||||||
File(), Variable(), Ip(), Family(), Constraints()... and so on.
|
File(), Variable(), Ip(), Family(), Constraints()... and so on.
|
||||||
|
"""
|
||||||
Rougail ObjectSpace is an object's reflexion of the XML elements"""
|
|
||||||
|
|
||||||
for dtd_elt in self.xmlreflector.dtd.iterelements():
|
for dtd_elt in self.xmlreflector.dtd.iterelements():
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
@ -138,12 +132,18 @@ class RougailObjSpace:
|
||||||
setattr(self, elt, type(name, (RootRougailObject,), dict()))
|
setattr(self, elt, type(name, (RootRougailObject,), dict()))
|
||||||
self.Leadership = self.leadership
|
self.Leadership = self.leadership
|
||||||
|
|
||||||
|
def display_xmlfiles(self,
|
||||||
|
xmlfiles: list,
|
||||||
|
) -> str:
|
||||||
|
if len(xmlfiles) == 1:
|
||||||
|
return '"' + xmlfiles[0] + '"'
|
||||||
|
return '"' + '", "'.join(xmlfiles[:-1]) + '"' + ' and ' + '"' + xmlfiles[-1] + '"'
|
||||||
|
|
||||||
def create_or_populate_from_xml(self,
|
def create_or_populate_from_xml(self,
|
||||||
namespace,
|
namespace,
|
||||||
xmlfolders,
|
xmlfolders,
|
||||||
):
|
):
|
||||||
"""Parses a bunch of XML files
|
"""Parses a bunch of XML files and populates the RougailObjSpace
|
||||||
populates the RougailObjSpace
|
|
||||||
"""
|
"""
|
||||||
for xmlfile, document in self.xmlreflector.load_xml_from_folders(xmlfolders):
|
for xmlfile, document in self.xmlreflector.load_xml_from_folders(xmlfolders):
|
||||||
self.redefine_variables = []
|
self.redefine_variables = []
|
||||||
|
@ -159,8 +159,7 @@ class RougailObjSpace:
|
||||||
space,
|
space,
|
||||||
namespace,
|
namespace,
|
||||||
):
|
):
|
||||||
"""Parses a Rougail XML file
|
"""Parses a Rougail XML file and populates the RougailObjSpace
|
||||||
populates the RougailObjSpace
|
|
||||||
"""
|
"""
|
||||||
# var to check unique family name in a XML file
|
# var to check unique family name in a XML file
|
||||||
family_names = []
|
family_names = []
|
||||||
|
@ -177,6 +176,7 @@ class RougailObjSpace:
|
||||||
# variables has no name, so force namespace name
|
# variables has no name, so force namespace name
|
||||||
child.attrib['name'] = namespace
|
child.attrib['name'] = namespace
|
||||||
if child.tag == 'value' and child.text is None:
|
if child.tag == 'value' and child.text is None:
|
||||||
|
# remove empty value
|
||||||
continue
|
continue
|
||||||
# variable objects creation
|
# variable objects creation
|
||||||
try:
|
try:
|
||||||
|
@ -223,7 +223,7 @@ class RougailObjSpace:
|
||||||
namespace,
|
namespace,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
instanciates or creates Rougail Object Subspace objects
|
retrieves or creates Rougail Object Subspace objects
|
||||||
"""
|
"""
|
||||||
obj = getattr(self, child.tag)
|
obj = getattr(self, child.tag)
|
||||||
if Redefinable in obj.__mro__:
|
if Redefinable in obj.__mro__:
|
||||||
|
@ -285,23 +285,17 @@ class RougailObjSpace:
|
||||||
return getattr(self, child.tag)(xmlfile)
|
return getattr(self, child.tag)(xmlfile)
|
||||||
raise DictConsistencyError(_(f'Redefined object in "{xmlfile}": "{name}" does not exist yet'))
|
raise DictConsistencyError(_(f'Redefined object in "{xmlfile}": "{name}" does not exist yet'))
|
||||||
|
|
||||||
def display_xmlfiles(self,
|
|
||||||
xmlfiles: list,
|
|
||||||
) -> str:
|
|
||||||
if len(xmlfiles) == 1:
|
|
||||||
return '"' + xmlfiles[0] + '"'
|
|
||||||
return '"' + '", "'.join(xmlfiles[:-1]) + '"' + ' and ' + '"' + xmlfiles[-1] + '"'
|
|
||||||
|
|
||||||
def get_existed_obj(self,
|
def get_existed_obj(self,
|
||||||
name: str,
|
name: str,
|
||||||
space: str,
|
space: str,
|
||||||
child,
|
child,
|
||||||
namespace: str,
|
namespace: str,
|
||||||
):
|
):
|
||||||
if isinstance(space, self.family): # pylint: disable=E1101
|
if isinstance(space, self.family):
|
||||||
if namespace != Config['variable_namespace']:
|
if namespace != Config['variable_namespace']:
|
||||||
name = space.path + '.' + name
|
name = space.path + '.' + name
|
||||||
if self.paths.path_is_defined(name):
|
if not self.paths.path_is_defined(name):
|
||||||
|
return
|
||||||
old_family_name = self.paths.get_variable_family_name(name)
|
old_family_name = self.paths.get_variable_family_name(name)
|
||||||
if namespace != Config['variable_namespace']:
|
if namespace != Config['variable_namespace']:
|
||||||
old_family_name = namespace + '.' + old_family_name
|
old_family_name = namespace + '.' + old_family_name
|
||||||
|
@ -309,21 +303,18 @@ class RougailObjSpace:
|
||||||
xmlfiles = self.display_xmlfiles(space.xmlfiles)
|
xmlfiles = self.display_xmlfiles(space.xmlfiles)
|
||||||
raise DictConsistencyError(_(f'Variable was previously create in family "{old_family_name}", now it is in "{space.path}" in {xmlfiles}'))
|
raise DictConsistencyError(_(f'Variable was previously create in family "{old_family_name}", now it is in "{space.path}" in {xmlfiles}'))
|
||||||
return self.paths.get_variable_obj(name)
|
return self.paths.get_variable_obj(name)
|
||||||
return
|
|
||||||
children = getattr(space, child.tag, {})
|
children = getattr(space, child.tag, {})
|
||||||
if name in children:
|
if name in children:
|
||||||
return children[name]
|
return children[name]
|
||||||
|
|
||||||
def convert_boolean(self, value): # pylint: disable=R0201
|
def convert_boolean(self, value):
|
||||||
"""Boolean coercion. The Rougail XML may contain srings like `True` or `False`
|
"""Boolean coercion. The Rougail XML may contain srings like `True` or `False`
|
||||||
"""
|
"""
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
return value
|
return value
|
||||||
if value == 'True':
|
if value == 'True':
|
||||||
return True
|
return True
|
||||||
elif value == 'False':
|
|
||||||
return False
|
return False
|
||||||
raise TypeError(_('{} is not True or False').format(value)) # pragma: no cover
|
|
||||||
|
|
||||||
def set_text(self,
|
def set_text(self,
|
||||||
child,
|
child,
|
||||||
|
@ -377,37 +368,37 @@ class RougailObjSpace:
|
||||||
if child.tag == 'fill' and child.attrib['target'] in self.redefine_variables:
|
if child.tag == 'fill' and child.attrib['target'] in self.redefine_variables:
|
||||||
self.remove_fill(child.attrib['target'])
|
self.remove_fill(child.attrib['target'])
|
||||||
|
|
||||||
def remove_check(self, name): # pylint: disable=C0111
|
def remove_check(self, name):
|
||||||
if hasattr(self.space, 'constraints') and hasattr(self.space.constraints, 'check'):
|
if hasattr(self.space, 'constraints') and hasattr(self.space.constraints, 'check'):
|
||||||
remove_checks = []
|
remove_checks = []
|
||||||
for idx, check in enumerate(self.space.constraints.check): # pylint: disable=E1101
|
for idx, check in enumerate(self.space.constraints.check):
|
||||||
if hasattr(check, 'target') and check.target == name:
|
if hasattr(check, 'target') and check.target == name:
|
||||||
remove_checks.append(idx)
|
remove_checks.append(idx)
|
||||||
|
|
||||||
remove_checks = list(set(remove_checks))
|
remove_checks = list(set(remove_checks))
|
||||||
remove_checks.sort(reverse=True)
|
remove_checks.sort(reverse=True)
|
||||||
for idx in remove_checks:
|
for idx in remove_checks:
|
||||||
self.space.constraints.check.pop(idx) # pylint: disable=E1101
|
self.space.constraints.check.pop(idx)
|
||||||
|
|
||||||
def remove_condition(self, name): # pylint: disable=C0111
|
def remove_condition(self, name):
|
||||||
remove_conditions = []
|
remove_conditions = []
|
||||||
for idx, condition in enumerate(self.space.constraints.condition): # pylint: disable=E1101
|
for idx, condition in enumerate(self.space.constraints.condition):
|
||||||
if condition.source == name:
|
if condition.source == name:
|
||||||
remove_conditions.append(idx)
|
remove_conditions.append(idx)
|
||||||
for idx in remove_conditions:
|
for idx in remove_conditions:
|
||||||
del self.space.constraints.condition[idx]
|
del self.space.constraints.condition[idx]
|
||||||
|
|
||||||
def remove_fill(self, name): # pylint: disable=C0111
|
def remove_fill(self, name):
|
||||||
if hasattr(self.space, 'constraints') and hasattr(self.space.constraints, 'fill'):
|
if hasattr(self.space, 'constraints') and hasattr(self.space.constraints, 'fill'):
|
||||||
remove_fills= []
|
remove_fills= []
|
||||||
for idx, fill in enumerate(self.space.constraints.fill): # pylint: disable=E1101
|
for idx, fill in enumerate(self.space.constraints.fill):
|
||||||
if hasattr(fill, 'target') and fill.target == name:
|
if hasattr(fill, 'target') and fill.target == name:
|
||||||
remove_fills.append(idx)
|
remove_fills.append(idx)
|
||||||
|
|
||||||
remove_fills = list(set(remove_fills))
|
remove_fills = list(set(remove_fills))
|
||||||
remove_fills.sort(reverse=True)
|
remove_fills.sort(reverse=True)
|
||||||
for idx in remove_fills:
|
for idx in remove_fills:
|
||||||
self.space.constraints.fill.pop(idx) # pylint: disable=E1101
|
self.space.constraints.fill.pop(idx)
|
||||||
|
|
||||||
def set_path(self,
|
def set_path(self,
|
||||||
space,
|
space,
|
||||||
|
@ -415,7 +406,7 @@ class RougailObjSpace:
|
||||||
namespace,
|
namespace,
|
||||||
document,
|
document,
|
||||||
variableobj,
|
variableobj,
|
||||||
): # pylint: disable=R0913
|
):
|
||||||
"""Fill self.paths attributes
|
"""Fill self.paths attributes
|
||||||
"""
|
"""
|
||||||
if child.tag == 'variable':
|
if child.tag == 'variable':
|
||||||
|
@ -449,7 +440,7 @@ class RougailObjSpace:
|
||||||
space,
|
space,
|
||||||
child,
|
child,
|
||||||
namespace,
|
namespace,
|
||||||
): # pylint: disable=R0201
|
):
|
||||||
if not hasattr(variableobj, 'index'):
|
if not hasattr(variableobj, 'index'):
|
||||||
variableobj.index = self.index
|
variableobj.index = self.index
|
||||||
variableobj.namespace = namespace
|
variableobj.namespace = namespace
|
||||||
|
@ -463,12 +454,11 @@ class RougailObjSpace:
|
||||||
else:
|
else:
|
||||||
setattr(space, child.tag, variableobj)
|
setattr(space, child.tag, variableobj)
|
||||||
|
|
||||||
def space_visitor(self, eosfunc_file): # pylint: disable=C0111
|
def space_visitor(self, eosfunc_file):
|
||||||
self.funcs_path = eosfunc_file
|
self.funcs_path = eosfunc_file
|
||||||
SpaceAnnotator(self, eosfunc_file)
|
SpaceAnnotator(self, eosfunc_file)
|
||||||
|
|
||||||
def save(self,
|
def save(self):
|
||||||
):
|
|
||||||
tiramisu_objects = TiramisuReflector(self.space,
|
tiramisu_objects = TiramisuReflector(self.space,
|
||||||
self.funcs_path,
|
self.funcs_path,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue