remove pylint comment

This commit is contained in:
Emmanuel Garette 2020-12-24 07:40:14 +01:00
parent ca40aa5ec3
commit fffd52eec6

View File

@ -4,11 +4,6 @@ as an input and outputs a Tiramisu's file
Sample usage::
eolobj.space_visitor(func)
xml = eolobj.save()
>>> from rougail.objspace import RougailObjSpace
>>> eolobj = RougailObjSpace('/usr/share/rougail/rougail.dtd')
>>> eolobj.create_or_populate_from_xml('rougail', ['/usr/share/rougail/dicos'])
@ -74,11 +69,10 @@ class ObjSpace:
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): # pylint: disable=R0912
def __init__(self, dtdfilename):
self.index = 0
self.space = ObjSpace()
self.paths = Path()
@ -91,13 +85,13 @@ class RougailObjSpace:
self.list_conditions = {}
self.booleans_attributs = []
self.make_object_space_class()
self.make_object_space_classes()
def make_object_space_class(self):
"""Create Rougail ObjectSpace class types, it enables us to create objects like:
def make_object_space_classes(self):
"""Create Rougail ObjectSpace class types from DDT file
It enables us to create objects like:
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():
attrs = {}
@ -138,12 +132,18 @@ class RougailObjSpace:
setattr(self, elt, type(name, (RootRougailObject,), dict()))
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,
namespace,
xmlfolders,
):
"""Parses a bunch of XML files
populates the RougailObjSpace
"""Parses a bunch of XML files and populates the RougailObjSpace
"""
for xmlfile, document in self.xmlreflector.load_xml_from_folders(xmlfolders):
self.redefine_variables = []
@ -159,8 +159,7 @@ class RougailObjSpace:
space,
namespace,
):
"""Parses a Rougail XML file
populates the RougailObjSpace
"""Parses a Rougail XML file and populates the RougailObjSpace
"""
# var to check unique family name in a XML file
family_names = []
@ -177,6 +176,7 @@ class RougailObjSpace:
# variables has no name, so force namespace name
child.attrib['name'] = namespace
if child.tag == 'value' and child.text is None:
# remove empty value
continue
# variable objects creation
try:
@ -223,7 +223,7 @@ class RougailObjSpace:
namespace,
):
"""
instanciates or creates Rougail Object Subspace objects
retrieves or creates Rougail Object Subspace objects
"""
obj = getattr(self, child.tag)
if Redefinable in obj.__mro__:
@ -285,45 +285,36 @@ class RougailObjSpace:
return getattr(self, child.tag)(xmlfile)
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,
name: str,
space: str,
child,
namespace: str,
):
if isinstance(space, self.family): # pylint: disable=E1101
if isinstance(space, self.family):
if namespace != Config['variable_namespace']:
name = space.path + '.' + name
if self.paths.path_is_defined(name):
old_family_name = self.paths.get_variable_family_name(name)
if namespace != Config['variable_namespace']:
old_family_name = namespace + '.' + old_family_name
if space.path != old_family_name:
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}'))
return self.paths.get_variable_obj(name)
return
if not self.paths.path_is_defined(name):
return
old_family_name = self.paths.get_variable_family_name(name)
if namespace != Config['variable_namespace']:
old_family_name = namespace + '.' + old_family_name
if space.path != old_family_name:
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}'))
return self.paths.get_variable_obj(name)
children = getattr(space, child.tag, {})
if name in children:
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`
"""
if isinstance(value, bool):
return value
if value == 'True':
return True
elif value == 'False':
return False
raise TypeError(_('{} is not True or False').format(value)) # pragma: no cover
return False
def set_text(self,
child,
@ -377,37 +368,37 @@ class RougailObjSpace:
if child.tag == 'fill' and child.attrib['target'] in self.redefine_variables:
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'):
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:
remove_checks.append(idx)
remove_checks = list(set(remove_checks))
remove_checks.sort(reverse=True)
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 = []
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:
remove_conditions.append(idx)
for idx in remove_conditions:
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'):
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:
remove_fills.append(idx)
remove_fills = list(set(remove_fills))
remove_fills.sort(reverse=True)
for idx in remove_fills:
self.space.constraints.fill.pop(idx) # pylint: disable=E1101
self.space.constraints.fill.pop(idx)
def set_path(self,
space,
@ -415,7 +406,7 @@ class RougailObjSpace:
namespace,
document,
variableobj,
): # pylint: disable=R0913
):
"""Fill self.paths attributes
"""
if child.tag == 'variable':
@ -449,7 +440,7 @@ class RougailObjSpace:
space,
child,
namespace,
): # pylint: disable=R0201
):
if not hasattr(variableobj, 'index'):
variableobj.index = self.index
variableobj.namespace = namespace
@ -463,12 +454,11 @@ class RougailObjSpace:
else:
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
SpaceAnnotator(self, eosfunc_file)
def save(self,
):
def save(self):
tiramisu_objects = TiramisuReflector(self.space,
self.funcs_path,
)