Table Of Contents

Previous topic

xmlobject.py

Next topic

text2data.py

This Page

operationmapping.py

class OperationMappingDef(XmlObject):

def __init__(self, typedef, schema, xmldata):

Initializes the operation mapping by processing the schema and xml documents:

>>> from simo.builder.importers.operation2modelchains import \
...     OperationMappingDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/operation2modelchains.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<SIMO_operation_mapping xmlns="http://www.simo-project.org/simo"
... xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
... xsi:schemaLocation="http://www.simo-project.org/simo
... ../schemas/operation_mapping.xsd">
... <operation>
...     <from>
...         <name>thinning</name>
...     </from>
...     <to>
...         <model_chain>Calculate thinning limits</model_chain>
...         <model_chain>Forced low thinning</model_chain>
...     </to>
... </operation>
... <operation>
...     <from>
...         <name>first_thinning</name>
...     </from>
...     <to>
...         <model_chain>Calculate thinning limits</model_chain>
...     </to>
... </operation>
... </SIMO_operation_mapping>'''
>>> class Lexicon(object):
...     def level_ind(self, level):
...         return 1
...     def variable_ind(self, level, var, active=False):
...         return (None, None)
>>> omd = OperationMappingDef(typedef)
>>> omd.schema = schema
>>> try:
...     omd.xml = ('testxml', xml, Lexicon())
... except ValueError, e:
...     print e
>>> omd.errors
set([])
>>> omd.xml['testxml'][:23]
u'<SIMO_operation_mapping'

def xml_to_obj(self, root, lexicon):

>>> om = omd.obj['testxml']
>>> from pprint import pprint
>>> pprint(om.operation_mapping)
{'first_thinning': ['Calculate thinning limits'],
 'thinning': ['Calculate thinning limits', 'Forced low thinning']}
>>> om.forced_op_chains
set(['Calculate thinning limits', 'Forced low thinning'])
>>> omd.errors
set([])
>>> omd.warnings
[]