Creole => Rougail

This commit is contained in:
Emmanuel Garette 2020-12-23 17:39:21 +01:00
parent ccc6924866
commit 54df7aca12
3 changed files with 30 additions and 34 deletions

View File

@ -1,5 +1,5 @@
#from .loader import load
from .objspace import CreoleObjSpace
from .objspace import RougailObjSpace
from .annotator import modes
__ALL__ = ('CreoleObjSpace', 'modes')
__ALL__ = ('RougailObjSpace', 'modes')

View File

@ -1,5 +1,5 @@
"""
Takes a bunch of Creole XML dispatched in differents folders
Takes a bunch of Rougail XML dispatched in differents folders
as an input and outputs a Tiramisu's file
Sample usage::
@ -9,24 +9,20 @@ Sample usage::
>>> from rougail.objspace import CreoleObjSpace
>>> eolobj = CreoleObjSpace('/usr/share/rougail/rougail.dtd')
>>> from rougail.objspace import RougailObjSpace
>>> eolobj = RougailObjSpace('/usr/share/rougail/rougail.dtd')
>>> eolobj.create_or_populate_from_xml('rougail', ['/usr/share/rougail/dicos'])
>>> eolobj.space_visitor('/usr/share/rougail/funcs.py')
>>> tiramisu = eolobj.save()
The CreoleObjSpace
The RougailObjSpace
- loads the XML into an internal CreoleObjSpace representation
- loads the XML into an internal RougailObjSpace representation
- visits/annotates the objects
- dumps the object space as Tiramisu string
The visit/annotation stage is a complex step that corresponds to the Creole
The visit/annotation stage is a complex step that corresponds to the Rougail
procedures.
For example: a variable is redefined and shall be moved to another family
means that a variable1 = Variable() object in the object space who lives in the family1 parent
has to be moved in family2. The visit procedure changes the varable1's object space's parent.
"""
from .i18n import _
from .xmlreflector import XMLReflector
@ -37,11 +33,11 @@ from .error import OperationError, SpaceObjShallNotBeUpdated, DictConsistencyErr
from .path import Path
from .config import Config
# CreoleObjSpace's elements like 'family' or 'follower', that shall be forced to the Redefinable type
# RougailObjSpace's elements like 'family' or 'follower', that shall be forced to the Redefinable type
FORCE_REDEFINABLES = ('family', 'follower', 'service', 'disknod', 'variables')
# CreoleObjSpace's elements that shall be forced to the UnRedefinable type
# RougailObjSpace's elements that shall be forced to the UnRedefinable type
FORCE_UNREDEFINABLES = ('value',)
# CreoleObjSpace's elements that shall be set to the UnRedefinable type
# RougailObjSpace's elements that shall be set to the UnRedefinable type
UNREDEFINABLE = ('multi', 'type')
FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value', 'target')
@ -49,32 +45,32 @@ FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value', 'target')
# _____________________________________________________________________________
# special types definitions for the Object Space's internal representation
class RootCreoleObject:
class RootRougailObject:
def __init__(self, xmlfiles):
if not isinstance(xmlfiles, list):
xmlfiles = [xmlfiles]
self.xmlfiles = xmlfiles
class Atom(RootCreoleObject):
class Atom(RootRougailObject):
pass
class Redefinable(RootCreoleObject):
class Redefinable(RootRougailObject):
pass
class UnRedefinable(RootCreoleObject):
class UnRedefinable(RootRougailObject):
pass
class CreoleObjSpace:
"""DOM XML reflexion free internal representation of a Creole Dictionary
class RougailObjSpace:
"""DOM XML reflexion free internal representation of a Rougail Dictionary
"""
choice = type('Choice', (RootCreoleObject,), dict())
property_ = type('Property', (RootCreoleObject,), dict())
# Creole ObjectSpace's Leadership variable class type
Leadership = type('Leadership', (RootCreoleObject,), dict())
choice = type('Choice', (RootRougailObject,), dict())
property_ = type('Property', (RootRougailObject,), dict())
# Rougail ObjectSpace's Leadership variable class type
Leadership = type('Leadership', (RootRougailObject,), dict())
"""
This Atom type stands for singleton, that is
an Object Space's atom object is present only once in the
@ -108,7 +104,7 @@ class CreoleObjSpace:
"""Create Rougail ObjectSpace class types, it enables us to create objects like:
File(), Variable(), Ip(), Family(), Constraints()... and so on.
Creole ObjectSpace is an object's reflexion of the XML elements"""
Rougail ObjectSpace is an object's reflexion of the XML elements"""
for dtd_elt in self.xmlreflector.dtd.iterelements():
attrs = {}
@ -148,7 +144,7 @@ class CreoleObjSpace:
xmlfolders,
):
"""Parses a bunch of XML files
populates the CreoleObjSpace
populates the RougailObjSpace
"""
for xmlfile, document in self.xmlreflector.load_xml_from_folders(xmlfolders):
self.redefine_variables = []
@ -166,8 +162,8 @@ class CreoleObjSpace:
space,
namespace,
):
"""Parses a Creole XML file
populates the CreoleObjSpace
"""Parses a Rougail XML file
populates the RougailObjSpace
"""
# var to check unique family name in a XML file
family_names = []
@ -230,7 +226,7 @@ class CreoleObjSpace:
namespace,
):
"""
instanciates or creates Creole Object Subspace objects
instanciates or creates Rougail Object Subspace objects
"""
obj = getattr(self, child.tag)
if Redefinable in obj.__mro__:
@ -322,7 +318,7 @@ class CreoleObjSpace:
return children[name]
def convert_boolean(self, value): # pylint: disable=R0201
"""Boolean coercion. The Creole XML may contain srings like `True` or `False`
"""Boolean coercion. The Rougail XML may contain srings like `True` or `False`
"""
if isinstance(value, bool):
return value
@ -372,7 +368,7 @@ class CreoleObjSpace:
child,
variableobj,
):
"""Creole object tree manipulations
"""Rougail object tree manipulations
"""
if child.tag == 'variable':
if child.attrib.get('remove_check', False):

View File

@ -54,7 +54,7 @@ def test_dir_error(request):
def launch_flattener(test_dir, test_ok=False):
eolobj = objspace.CreoleObjSpace(Config['dtdfilename'])
eolobj = objspace.RougailObjSpace(Config['dtdfilename'])
dirs = [test_dir]
subfolder = join(test_dir, 'subfolder')
if isdir(subfolder):
@ -113,4 +113,4 @@ def test_error_dictionary(test_dir_error):
def test_no_dtd():
with raises(IOError):
eolobj = objspace.CreoleObjSpace('notexists.dtd')
eolobj = objspace.RougailObjSpace('notexists.dtd')