Creole => Rougail
This commit is contained in:
parent
ccc6924866
commit
54df7aca12
|
@ -1,5 +1,5 @@
|
||||||
#from .loader import load
|
#from .loader import load
|
||||||
from .objspace import CreoleObjSpace
|
from .objspace import RougailObjSpace
|
||||||
from .annotator import modes
|
from .annotator import modes
|
||||||
|
|
||||||
__ALL__ = ('CreoleObjSpace', 'modes')
|
__ALL__ = ('RougailObjSpace', 'modes')
|
||||||
|
|
|
@ -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
|
as an input and outputs a Tiramisu's file
|
||||||
|
|
||||||
Sample usage::
|
Sample usage::
|
||||||
|
@ -9,24 +9,20 @@ Sample usage::
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
>>> from rougail.objspace import CreoleObjSpace
|
>>> from rougail.objspace import RougailObjSpace
|
||||||
>>> eolobj = CreoleObjSpace('/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'])
|
||||||
>>> eolobj.space_visitor('/usr/share/rougail/funcs.py')
|
>>> eolobj.space_visitor('/usr/share/rougail/funcs.py')
|
||||||
>>> tiramisu = eolobj.save()
|
>>> 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
|
- visits/annotates the objects
|
||||||
- dumps the object space as Tiramisu string
|
- 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.
|
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 .i18n import _
|
||||||
from .xmlreflector import XMLReflector
|
from .xmlreflector import XMLReflector
|
||||||
|
@ -37,11 +33,11 @@ from .error import OperationError, SpaceObjShallNotBeUpdated, DictConsistencyErr
|
||||||
from .path import Path
|
from .path import Path
|
||||||
from .config import Config
|
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')
|
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',)
|
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')
|
UNREDEFINABLE = ('multi', 'type')
|
||||||
|
|
||||||
FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value', 'target')
|
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
|
# special types definitions for the Object Space's internal representation
|
||||||
class RootCreoleObject:
|
class RootRougailObject:
|
||||||
def __init__(self, xmlfiles):
|
def __init__(self, xmlfiles):
|
||||||
if not isinstance(xmlfiles, list):
|
if not isinstance(xmlfiles, list):
|
||||||
xmlfiles = [xmlfiles]
|
xmlfiles = [xmlfiles]
|
||||||
self.xmlfiles = xmlfiles
|
self.xmlfiles = xmlfiles
|
||||||
|
|
||||||
|
|
||||||
class Atom(RootCreoleObject):
|
class Atom(RootRougailObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Redefinable(RootCreoleObject):
|
class Redefinable(RootRougailObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UnRedefinable(RootCreoleObject):
|
class UnRedefinable(RootRougailObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CreoleObjSpace:
|
class RougailObjSpace:
|
||||||
"""DOM XML reflexion free internal representation of a Creole Dictionary
|
"""DOM XML reflexion free internal representation of a Rougail Dictionary
|
||||||
"""
|
"""
|
||||||
choice = type('Choice', (RootCreoleObject,), dict())
|
choice = type('Choice', (RootRougailObject,), dict())
|
||||||
property_ = type('Property', (RootCreoleObject,), dict())
|
property_ = type('Property', (RootRougailObject,), dict())
|
||||||
# Creole ObjectSpace's Leadership variable class type
|
# Rougail ObjectSpace's Leadership variable class type
|
||||||
Leadership = type('Leadership', (RootCreoleObject,), dict())
|
Leadership = type('Leadership', (RootRougailObject,), dict())
|
||||||
"""
|
"""
|
||||||
This Atom type stands for singleton, that is
|
This Atom type stands for singleton, that is
|
||||||
an Object Space's atom object is present only once in the
|
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:
|
"""Create Rougail ObjectSpace class types, it enables us to create objects like:
|
||||||
File(), Variable(), Ip(), Family(), Constraints()... and so on.
|
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():
|
for dtd_elt in self.xmlreflector.dtd.iterelements():
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
@ -148,7 +144,7 @@ class CreoleObjSpace:
|
||||||
xmlfolders,
|
xmlfolders,
|
||||||
):
|
):
|
||||||
"""Parses a bunch of XML files
|
"""Parses a bunch of XML files
|
||||||
populates the CreoleObjSpace
|
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 = []
|
||||||
|
@ -166,8 +162,8 @@ class CreoleObjSpace:
|
||||||
space,
|
space,
|
||||||
namespace,
|
namespace,
|
||||||
):
|
):
|
||||||
"""Parses a Creole XML file
|
"""Parses a Rougail XML file
|
||||||
populates the CreoleObjSpace
|
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 = []
|
||||||
|
@ -230,7 +226,7 @@ class CreoleObjSpace:
|
||||||
namespace,
|
namespace,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
instanciates or creates Creole Object Subspace objects
|
instanciates 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__:
|
||||||
|
@ -322,7 +318,7 @@ class CreoleObjSpace:
|
||||||
return children[name]
|
return children[name]
|
||||||
|
|
||||||
def convert_boolean(self, value): # pylint: disable=R0201
|
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):
|
if isinstance(value, bool):
|
||||||
return value
|
return value
|
||||||
|
@ -372,7 +368,7 @@ class CreoleObjSpace:
|
||||||
child,
|
child,
|
||||||
variableobj,
|
variableobj,
|
||||||
):
|
):
|
||||||
"""Creole object tree manipulations
|
"""Rougail object tree manipulations
|
||||||
"""
|
"""
|
||||||
if child.tag == 'variable':
|
if child.tag == 'variable':
|
||||||
if child.attrib.get('remove_check', False):
|
if child.attrib.get('remove_check', False):
|
||||||
|
|
|
@ -54,7 +54,7 @@ def test_dir_error(request):
|
||||||
|
|
||||||
|
|
||||||
def launch_flattener(test_dir, test_ok=False):
|
def launch_flattener(test_dir, test_ok=False):
|
||||||
eolobj = objspace.CreoleObjSpace(Config['dtdfilename'])
|
eolobj = objspace.RougailObjSpace(Config['dtdfilename'])
|
||||||
dirs = [test_dir]
|
dirs = [test_dir]
|
||||||
subfolder = join(test_dir, 'subfolder')
|
subfolder = join(test_dir, 'subfolder')
|
||||||
if isdir(subfolder):
|
if isdir(subfolder):
|
||||||
|
@ -113,4 +113,4 @@ def test_error_dictionary(test_dir_error):
|
||||||
|
|
||||||
def test_no_dtd():
|
def test_no_dtd():
|
||||||
with raises(IOError):
|
with raises(IOError):
|
||||||
eolobj = objspace.CreoleObjSpace('notexists.dtd')
|
eolobj = objspace.RougailObjSpace('notexists.dtd')
|
||||||
|
|
Loading…
Reference in New Issue