create a new Rougail object
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
#from .loader import load
|
||||
from .objspace import RougailObjSpace
|
||||
from .rougail import Rougail
|
||||
from .annotator import modes
|
||||
|
||||
__ALL__ = ('RougailObjSpace', 'modes')
|
||||
|
@ -1,33 +1,10 @@
|
||||
"""
|
||||
Takes a bunch of Rougail XML dispatched in differents folders
|
||||
as an input and outputs a Tiramisu's file
|
||||
|
||||
Sample usage::
|
||||
|
||||
>>> 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 RougailObjSpace
|
||||
|
||||
- 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 Rougail
|
||||
procedures.
|
||||
"""
|
||||
|
||||
from typing import List
|
||||
|
||||
from .i18n import _
|
||||
from .xmlreflector import XMLReflector
|
||||
from .annotator import SpaceAnnotator
|
||||
from .tiramisureflector import TiramisuReflector
|
||||
from .utils import normalize_family
|
||||
from .error import OperationError, SpaceObjShallNotBeUpdated, DictConsistencyError
|
||||
from .error import SpaceObjShallNotBeUpdated, DictConsistencyError
|
||||
from .path import Path
|
||||
from .config import Config
|
||||
|
||||
@ -75,12 +52,13 @@ class RougailObjSpace:
|
||||
"""Rougail ObjectSpace is an object's reflexion of the XML elements
|
||||
"""
|
||||
|
||||
def __init__(self, dtdfilename):
|
||||
def __init__(self,
|
||||
xmlreflector: XMLReflector,
|
||||
) -> None:
|
||||
self.index = 0
|
||||
self.xmlreflector = xmlreflector
|
||||
self.space = ObjSpace()
|
||||
self.paths = Path()
|
||||
self.xmlreflector = XMLReflector()
|
||||
self.xmlreflector.parse_dtd(dtdfilename)
|
||||
self.redefine_variables = None
|
||||
|
||||
self.forced_text_elts = set()
|
||||
@ -142,21 +120,6 @@ class RougailObjSpace:
|
||||
return '"' + xmlfiles[0] + '"'
|
||||
return '"' + '", "'.join(xmlfiles[:-1]) + '"' + ' and ' + '"' + xmlfiles[-1] + '"'
|
||||
|
||||
def create_or_populate_from_xml(self,
|
||||
namespace: str,
|
||||
xmlfolders: List[str],
|
||||
) -> List[str]:
|
||||
"""Parses a bunch of XML files and populates the RougailObjSpace
|
||||
"""
|
||||
for xmlfile in self.xmlreflector.load_xml_from_folders(xmlfolders):
|
||||
document = self.xmlreflector.parse_xmlfile(xmlfile)
|
||||
self.redefine_variables = []
|
||||
self.xml_parse_document(xmlfile,
|
||||
document,
|
||||
self.space,
|
||||
namespace,
|
||||
)
|
||||
|
||||
def xml_parse_document(self,
|
||||
xmlfile,
|
||||
document,
|
||||
@ -457,13 +420,3 @@ class RougailObjSpace:
|
||||
getattr(space, child.tag).append(variableobj)
|
||||
else:
|
||||
setattr(space, child.tag, variableobj)
|
||||
|
||||
def space_visitor(self, eosfunc_file):
|
||||
self.funcs_path = eosfunc_file
|
||||
SpaceAnnotator(self, eosfunc_file)
|
||||
|
||||
def save(self):
|
||||
tiramisu_objects = TiramisuReflector(self.space,
|
||||
self.funcs_path,
|
||||
)
|
||||
return tiramisu_objects.get_text() + '\n'
|
||||
|
63
src/rougail/rougail.py
Normal file
63
src/rougail/rougail.py
Normal file
@ -0,0 +1,63 @@
|
||||
"""
|
||||
Takes a bunch of Rougail XML dispatched in differents folders
|
||||
as an input and outputs a Tiramisu's file
|
||||
|
||||
Sample usage::
|
||||
|
||||
>>> from rougail import Rougail
|
||||
>>> rougail = Rougail('/usr/share/rougail/rougail.dtd')
|
||||
>>> rougail.create_or_populate_from_xml('rougail', ['/usr/share/rougail/dicos'])
|
||||
>>> rougail.space_visitor('/usr/share/rougail/funcs.py')
|
||||
>>> tiramisu = rougail.save()
|
||||
|
||||
The Rougail
|
||||
|
||||
- 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 Rougail
|
||||
procedures.
|
||||
"""
|
||||
|
||||
from typing import List
|
||||
from .objspace import RougailObjSpace
|
||||
from .xmlreflector import XMLReflector
|
||||
from .tiramisureflector import TiramisuReflector
|
||||
from .annotator import SpaceAnnotator
|
||||
|
||||
|
||||
class Rougail:
|
||||
def __init__(self,
|
||||
dtdfilename: str,
|
||||
) -> None:
|
||||
self.xmlreflector = XMLReflector()
|
||||
self.xmlreflector.parse_dtd(dtdfilename)
|
||||
self.rougailobjspace = RougailObjSpace(self.xmlreflector)
|
||||
|
||||
def create_or_populate_from_xml(self,
|
||||
namespace: str,
|
||||
xmlfolders: List[str],
|
||||
) -> List[str]:
|
||||
"""Parses a bunch of XML files and populates the RougailObjSpace
|
||||
"""
|
||||
for xmlfile in self.xmlreflector.load_xml_from_folders(xmlfolders):
|
||||
document = self.xmlreflector.parse_xmlfile(xmlfile)
|
||||
self.rougailobjspace.redefine_variables = []
|
||||
self.rougailobjspace.xml_parse_document(xmlfile,
|
||||
document,
|
||||
self.rougailobjspace.space,
|
||||
namespace,
|
||||
)
|
||||
|
||||
def space_visitor(self,
|
||||
eosfunc_file: str,
|
||||
) -> None:
|
||||
self.funcs_path = eosfunc_file
|
||||
SpaceAnnotator(self.rougailobjspace, eosfunc_file)
|
||||
|
||||
def save(self) -> str:
|
||||
tiramisu_objects = TiramisuReflector(self.rougailobjspace.space,
|
||||
self.funcs_path,
|
||||
)
|
||||
return tiramisu_objects.get_text() + '\n'
|
Reference in New Issue
Block a user