xmlclass/xmlclass.py
author lbessard
Thu, 19 Jul 2007 15:04:41 +0200
changeset 46 4379e98a30aa
parent 24 364320323b4d
child 58 39cd981ff242
permissions -rw-r--r--
Bug on SFC generation fixed
Adding Action and Transition remove functions
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     3
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     6
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     7
#Copyright (C): Edouard TISSERANT and Laurent BESSARD
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     8
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    10
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    15
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    19
#Lesser General Public License for more details.
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    20
#
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    24
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    25
from xml.dom import minidom
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    26
import sys,re
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    27
from types import *
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    28
from datetime import *
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    29
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    30
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    31
Time and date definitions
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    32
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    33
TimeType = time(0,0,0).__class__
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    34
DateType = date(1,1,1).__class__
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    35
DateTimeType = datetime(1,1,1,0,0,0).__class__
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    36
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    37
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    38
Regular expression models for extracting dates and times from a string
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    39
"""
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
    40
time_model = re.compile('([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    41
date_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})')
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
    42
datetime_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})[ T]([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    43
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    44
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    45
Dictionaries for stocking Classes and Types created from XML
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    46
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    47
XMLClasses = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    48
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    49
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    50
This function calculates the number of whitespace for indentation
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    51
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    52
def getIndent(indent, balise):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    53
    first = indent * 2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    54
    second = first + len(balise) + 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    55
    return "\t".expandtabs(first), "\t".expandtabs(second)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    56
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    57
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    58
This function opens the xsd file and generate the classes from the xml tree
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    59
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    60
def GenerateClassesFromXSD(filename):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    61
    xsdfile = open(filename, 'r')
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    62
    Generate_xsd_classes(minidom.parse(xsdfile), None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    63
    xsdfile.close()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    64
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    65
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    66
This function recursively creates a definition of the classes and their attributes
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    67
for plcopen from the xsd file of plcopen opened in a DOM model
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    68
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    69
def Generate_xsd_classes(tree, parent, sequence = False):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    70
    attributes = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    71
    inheritance = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    72
    if sequence:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    73
        order = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    74
    # The lists of attributes and inheritance of the node are generated from the childrens 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    75
    for node in tree.childNodes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    76
        # We make fun of #text elements and all other tags that don't are xsd tags
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    77
        if node.nodeName != "#text" and node.nodeName.startswith("xsd:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    78
            recursion = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    79
            name = node.nodeName[4:].encode()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    80
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    81
            # This tags defines an attribute of the class
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    82
            if name in ["element", "attribute"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    83
                nodename = GetAttributeValue(node._attrs["name"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    84
                if "type" in node._attrs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    85
                    nodetype = GetAttributeValue(node._attrs["type"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    86
                    if nodetype.startswith("xsd"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    87
                        nodetype = nodetype.replace("xsd", "bse")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    88
                    elif nodetype.startswith("ppx"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    89
                        nodetype = nodetype.replace("ppx", "cls")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    90
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    91
                    # The type of attribute is defines in the child tree so we generate a new class
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    92
                    # No name is defined so we create one from nodename and parent class name
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    93
                    # (because some different nodes can have the same name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    94
                    if parent:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    95
                        classname = "%s_%s"%(parent, nodename)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    96
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    97
                        classname = nodename
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    98
                    Generate_xsd_classes(node, classname)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
    99
                    nodetype = "cls:%s"%classname
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   100
                if name == "attribute":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   101
                    if "use" in node._attrs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   102
                        use = GetAttributeValue(node._attrs["use"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   103
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   104
                        use = "optional"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   105
                if name == "element":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   106
                    # If a tag can be written more than one time we define a list attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   107
                    if "maxOccurs" in node._attrs and GetAttributeValue(node._attrs["maxOccurs"]) == "unbounded":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   108
                        nodetype = "%s[]"%nodetype
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   109
                    if "minOccurs" in node._attrs and GetAttributeValue(node._attrs["minOccurs"]) == "0":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   110
                        use = "optional"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   111
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   112
                        use = "required"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   113
                attributes[nodename] = (nodetype, name, use)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   114
                if sequence:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   115
                    order.append(nodename)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   116
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   117
            # This tag defines a new class
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   118
            elif name == "complexType" or name == "simpleType":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   119
                if "name" in node._attrs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   120
                    classname = GetAttributeValue(node._attrs["name"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   121
                    super, attrs = Generate_xsd_classes(node, classname)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   122
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   123
                    classname = parent
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   124
                    super, attrs = Generate_xsd_classes(node, classname.split("_")[-1])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   125
                # When all attributes and inheritances have been extracted, the
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   126
                # values are added in the list of classes to create
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   127
                if classname not in XMLClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   128
                    XMLClasses[classname] = (super, attrs)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   129
                elif XMLClasses[classname] != (super, attrs):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   130
                    print "A different class has already got %s for name"%classname
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   131
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   132
            # This tag defines an attribute that can have different types
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   133
            elif name == "choice":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   134
                super, attrs = Generate_xsd_classes(node, parent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   135
                if "ref" in attrs.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   136
                    choices = attrs
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   137
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   138
                    choices = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   139
                    for attr, (attr_type, xml_type, write_type) in attrs.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   140
                        choices[attr] = attr_type
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   141
                if "maxOccurs" in node._attrs and GetAttributeValue(node._attrs["maxOccurs"]) == "unbounded":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   142
                    attributes["multichoice_content"] = choices
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   143
                    if sequence:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   144
                        order.append("multichoice_content")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   145
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   146
                    attributes["choice_content"] = choices
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   147
                    if sequence:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   148
                        order.append("choice_content")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   149
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   150
            # This tag defines the order in which class attributes must be written
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   151
            # in plcopen xml file. We have to store this order like an attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   152
            elif name in "sequence":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   153
                super, attrs, order = Generate_xsd_classes(node, parent, True)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   154
                if "maxOccurs" in node._attrs and GetAttributeValue(node._attrs["maxOccurs"]) == "unbounded":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   155
                    for attr, (attr_type, xml_type, write_type) in attrs.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   156
                        attrs[attr] = ("%s[]"%attr_type, xml_type, write_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   157
                if "minOccurs" in node._attrs and GetAttributeValue(node._attrs["minOccurs"]) == "0":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   158
                    for attr, (attr_type, xml_type, write_type) in attrs.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   159
                        attrs[attr] = (attr_type, xml_type, "optional")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   160
                inheritance.extend(super)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   161
                attributes.update(attrs)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   162
                attributes["order"] = order
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   163
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   164
            # This tag defines of types
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   165
            elif name == "group":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   166
                if "name" in node._attrs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   167
                    nodename = GetAttributeValue(node._attrs["name"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   168
                    super, attrs = Generate_xsd_classes(node, None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   169
                    XMLClasses[nodename] = (super, {"group":attrs["choice_content"]})
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   170
                elif "ref" in node._attrs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   171
                    if "ref" not in attributes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   172
                        attributes["ref"] = [GetAttributeValue(node._attrs["ref"])]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   173
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   174
                        attributes["ref"].append(GetAttributeValue(node._attrs["ref"]))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   175
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   176
            # This tag define a base class for the node
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   177
            elif name == "extension":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   178
                super = GetAttributeValue(node._attrs["base"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   179
                if super.startswith("xsd"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   180
                    super = super.replace("xsd", "bse")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   181
                elif super.startswith("ppx"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   182
                    super = super.replace("ppx", "cls")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   183
                inheritance.append(super[4:])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   184
                recursion = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   185
                
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   186
            # This tag defines a restriction on the type of attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   187
            elif name == "restriction":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   188
                basetype = GetAttributeValue(node._attrs["base"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   189
                if basetype.startswith("xsd"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   190
                    basetype = basetype.replace("xsd", "bse")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   191
                elif basetype.startswith("ppx"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   192
                    basetype = basetype.replace("ppx", "cls")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   193
                attributes["basetype"] = basetype
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   194
                recursion = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   195
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   196
            # This tag defines an enumerated type
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   197
            elif name == "enumeration":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   198
                if "enum" not in attributes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   199
                    attributes["enum"] = [GetAttributeValue(node._attrs["value"])]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   200
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   201
                    attributes["enum"].append(GetAttributeValue(node._attrs["value"]))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   202
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   203
            # This tags defines a restriction on a numerical value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   204
            elif name in ["minInclusive","maxInclusive"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   205
                if "limit" not in attributes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   206
                    attributes["limit"] = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   207
                if name == "minInclusive":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   208
                    attributes["limit"]["min"] = eval(GetAttributeValue(node._attrs["value"]))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   209
                elif name == "maxInclusive":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   210
                    attributes["limit"]["max"] = eval(GetAttributeValue(node._attrs["value"]))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   211
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   212
            # This tag are not important but their childrens are. The childrens are then parsed. 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   213
            elif name in ["complexContent", "schema"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   214
                recursion = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   215
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   216
            # We make fun of xsd documentation
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   217
            elif name in ["annotation"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   218
                pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   219
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   220
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   221
                #print name
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   222
                Generate_xsd_classes(node, parent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   223
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   224
            # Parse the childrens of node
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   225
            if recursion:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   226
                super, attrs = Generate_xsd_classes(node, parent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   227
                inheritance.extend(super)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   228
                attributes.update(attrs)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   229
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   230
    # if sequence tag have been found, order is returned
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   231
    if sequence:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   232
        return inheritance, attributes, order
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   233
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   234
        return inheritance, attributes
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   235
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   236
Function that extracts data from a node
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   237
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   238
def GetAttributeValue(attr):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   239
    if len(attr.childNodes) == 1:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   240
        return attr.childNodes[0].data.encode()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   241
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   242
        return ""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   243
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   244
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   245
Funtion that returns the Python type and default value for a given type
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   246
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   247
def GetTypeInitialValue(attr_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   248
    type_compute = attr_type[4:].replace("[]", "")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   249
    if attr_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   250
        if type_compute == "boolean":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   251
            return BooleanType, "False"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   252
        elif type_compute in ["decimal","unsignedLong","long","integer"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   253
            return IntType, "0"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   254
        elif type_compute in ["string","anyURI","NMTOKEN"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   255
            return StringType, "\"\""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   256
        elif type_compute == "time":
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   257
            return TimeType, "time(0,0,0,0)"
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   258
        elif type_compute == "date":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   259
            return DateType, "date(1,1,1)"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   260
        elif type_compute == "dateTime":
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   261
            return DateTimeType, "datetime(1,1,1,0,0,0,0)"
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   262
        elif type_compute == "language":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   263
            return StringType, "\"en-US\""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   264
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   265
            print "Can't affect: %s"%type_compute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   266
    elif attr_type.startswith("cls:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   267
        if type_compute in XMLClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   268
            return XMLClasses[type_compute],"%s()"%type_compute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   269
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   270
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   271
Function that computes value from a python type (Only Boolean are critical because
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   272
there is no uppercase in plcopen)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   273
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   274
def ComputeValue(value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   275
    if type(value) == BooleanType:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   276
        if value:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   277
            return "true"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   278
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   279
            return "false"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   280
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   281
        return str(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   282
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   283
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   284
Function that extracts a value from a string following the xsd type given
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   285
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   286
def GetComputedValue(attr_type, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   287
    type_compute = attr_type[4:].replace("[]", "")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   288
    if type_compute == "boolean":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   289
         if value == "true":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   290
             return True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   291
         elif value == "false":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   292
             return False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   293
         else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   294
            raise ValueError, "\"%s\" is not a valid boolean!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   295
    elif type_compute in ["decimal","unsignedLong","long","integer"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   296
        return int(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   297
    elif type_compute in ["string","anyURI","NMTOKEN","language"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   298
        return value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   299
    elif type_compute == "time":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   300
        result = time_model.match(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   301
        if result:
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   302
            values = result.groups()
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   303
            time_values = [int(v) for v in values[:2]]
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   304
            seconds = float(values[2])
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   305
            time_values.extend([int(seconds), int((seconds % 1) * 1000000)])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   306
            return time(*time_values)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   307
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   308
            raise ValueError, "\"%s\" is not a valid time!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   309
    elif type_compute == "date":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   310
        result = date_model.match(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   311
        if result:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   312
            date_values = [int(v) for v in result.groups()]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   313
            return date(*date_values)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   314
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   315
            raise ValueError, "\"%s\" is not a valid date!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   316
    elif type_compute == "dateTime":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   317
        result = datetime_model.match(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   318
        if result:
24
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   319
            values = result.groups()
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   320
            datetime_values = [int(v) for v in values[:5]]
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   321
            seconds = float(values[5])
364320323b4d Adding support for date and time data types
lbessard
parents: 2
diff changeset
   322
            datetime_values.extend([int(seconds), int((seconds % 1) * 1000000)])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   323
            return datetime(*datetime_values)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   324
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   325
            raise ValueError, "\"%s\" is not a valid datetime!"%value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   326
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   327
        print "Can't affect: %s"%type_compute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   328
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   329
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   330
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   331
This is the Metaclass for PLCOpen element classes. It generates automatically
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   332
the basic useful methods for manipulate the differents attributes of the classes
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   333
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   334
class MetaClass(type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   335
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   336
    def __init__(cls, name, bases, dict, user_classes):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   337
        super(MetaClass, cls).__init__(name, bases, {})
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   338
        #print name, bases, dict, "\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   339
        initialValues = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   340
        for attr, values in dict.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   341
            if attr in ["order", "basetype"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   342
                pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   343
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   344
            # Class is a enumerated type
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   345
            elif attr == "enum":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   346
                value_type, initial = GetTypeInitialValue(dict["basetype"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   347
                initialValues["value"] = "\"%s\""%values[0]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   348
                setattr(cls, "value", values[0])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   349
                setattr(cls, "setValue", MetaClass.generateSetEnumMethod(cls, values, value_type))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   350
                setattr(cls, "getValue", MetaClass.generateGetMethod(cls, "value"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   351
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   352
            # Class is a limited type
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   353
            elif attr == "limit":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   354
                value_type, initial = GetTypeInitialValue(dict["basetype"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   355
                initial = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   356
                if "min" in values:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   357
                    initial = max(initial, values["min"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   358
                if "max" in values:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   359
                    initial = min(initial, values["max"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   360
                initialValues["value"] = "%d"%initial
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   361
                setattr(cls, "value", initial)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   362
                setattr(cls, "setValue", MetaClass.generateSetLimitMethod(cls, values, value_type))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   363
                setattr(cls, "getValue", MetaClass.generateGetMethod(cls, "value"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   364
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   365
            # Class has an attribute that can have different value types
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   366
            elif attr == "choice_content":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   367
                setattr(cls, "content", None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   368
                initialValues["content"] = "None"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   369
                setattr(cls, "deleteContent", MetaClass.generateDeleteMethod(cls, "content"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   370
                setattr(cls, "setContent", MetaClass.generateSetChoiceMethod(cls, values))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   371
                setattr(cls, "getContent", MetaClass.generateGetMethod(cls, "content"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   372
            elif attr == "multichoice_content":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   373
                setattr(cls, "content", [])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   374
                initialValues["content"] = "[]"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   375
                setattr(cls, "appendContent", MetaClass.generateAppendChoiceMethod(cls, values))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   376
                setattr(cls, "insertContent", MetaClass.generateInsertChoiceMethod(cls, values))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   377
                setattr(cls, "removeContent", MetaClass.generateRemoveMethod(cls, "content"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   378
                setattr(cls, "countContent", MetaClass.generateCountMethod(cls, "content"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   379
                setattr(cls, "setContent", MetaClass.generateSetMethod(cls, "content", ListType))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   380
                setattr(cls, "getContent", MetaClass.generateGetMethod(cls, "content"))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   381
            
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   382
            # It's an attribute of the class
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   383
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   384
                attrname = attr[0].upper()+attr[1:]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   385
                attr_type, xml_type, write_type = values
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   386
                value_type, initial = GetTypeInitialValue(attr_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   387
                # Value of the attribute is a list
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   388
                if attr_type.endswith("[]"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   389
                    setattr(cls, attr, [])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   390
                    initialValues[attr] = "[]"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   391
                    setattr(cls, "append"+attrname, MetaClass.generateAppendMethod(cls, attr, value_type))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   392
                    setattr(cls, "insert"+attrname, MetaClass.generateInsertMethod(cls, attr, value_type))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   393
                    setattr(cls, "remove"+attrname, MetaClass.generateRemoveMethod(cls, attr))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   394
                    setattr(cls, "count"+attrname, MetaClass.generateCountMethod(cls, attr))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   395
                    setattr(cls, "set"+attrname, MetaClass.generateSetMethod(cls, attr, ListType))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   396
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   397
                    if write_type == "optional":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   398
                        setattr(cls, attr, None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   399
                        initialValues[attr] = "None"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   400
                        setattr(cls, "add"+attrname, MetaClass.generateAddMethod(cls, attr, initial, user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   401
                        setattr(cls, "delete"+attrname, MetaClass.generateDeleteMethod(cls, attr))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   402
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   403
                        setattr(cls, attr, initial)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   404
                        initialValues[attr] = initial
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   405
                    setattr(cls, "set"+attrname, MetaClass.generateSetMethod(cls, attr, value_type))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   406
                setattr(cls, "get"+attrname, MetaClass.generateGetMethod(cls, attr))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   407
        setattr(cls, "__init__", MetaClass.generateInitMethod(cls, bases, initialValues, user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   408
        setattr(cls, "loadXMLTree", MetaClass.generateLoadXMLTree(cls, bases, dict, user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   409
        setattr(cls, "generateXMLText", MetaClass.generateGenerateXMLText(cls, bases, dict))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   410
        setattr(cls, "singleLineAttributes", True)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   411
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   412
    """
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   413
    Method that generate the method for loading an xml tree by following the
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   414
    attributes list defined
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   415
    """
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   416
    def generateLoadXMLTree(cls, bases, dict, user_classes):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   417
        def loadXMLTreeMethod(self, tree):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   418
            # If class is derived, values of inheritance classes are loaded
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   419
            for base in bases:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   420
                base.loadXMLTree(self, tree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   421
            # Class is a enumerated or limited value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   422
            if "enum" in dict.keys() or "limit" in dict.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   423
                attr_value = GetAttributeValue(tree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   424
                attr_type = dict["basetype"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   425
                val = GetComputedValue(attr_type, attr_value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   426
                self.setValue(val)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   427
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   428
                
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   429
                # Load the node attributes if they are defined in the list
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   430
                for attrname, attr in tree._attrs.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   431
                    if attrname in dict.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   432
                        attr_type, xml_type, write_type = dict[attrname]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   433
                        attr_value = GetAttributeValue(attr)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   434
                        if write_type != "optional" or attr_value != "":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   435
                            # Extracts the value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   436
                            if attr_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   437
                                val = GetComputedValue(attr_type, attr_value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   438
                            elif attr_type.startswith("cls:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   439
                                val = eval("%s()"%attr_type[4:], globals().update(user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   440
                                val.loadXMLTree(attr)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   441
                            setattr(self, attrname, val)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   442
                
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   443
                # Load the node childs if they are defined in the list
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   444
                for node in tree.childNodes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   445
                    name = node.nodeName
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   446
                    # We make fun of #text elements
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   447
                    if name != "#text":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   448
                        
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   449
                        # Class has an attribute that can have different value types
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   450
                        if "choice_content" in dict.keys() and name in dict["choice_content"].keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   451
                            attr_type = dict["choice_content"][name]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   452
                            # Extracts the value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   453
                            if attr_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   454
                                attr_value = GetAttributeValue(node)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   455
                                if write_type != "optional" or attr_value != "":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   456
                                    val = GetComputedValue(attr_type.replace("[]",""), attr_value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   457
                                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   458
                                    val = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   459
                            elif attr_type.startswith("cls:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   460
                                val = eval("%s()"%attr_type[4:].replace("[]",""), globals().update(user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   461
                                val.loadXMLTree(node)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   462
                            # Stock value in content attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   463
                            if val:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   464
                                if attr_type.endswith("[]"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   465
                                    if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   466
                                        self.content["value"].append(val)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   467
                                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   468
                                        self.content = {"name":name,"value":[val]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   469
                                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   470
                                    self.content = {"name":name,"value":val}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   471
                        
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   472
                        # Class has a list of attributes that can have different value types
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   473
                        elif "multichoice_content" in dict.keys() and name in dict["multichoice_content"].keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   474
                            attr_type = dict["multichoice_content"][name]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   475
                            # Extracts the value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   476
                            if attr_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   477
                                attr_value = GetAttributeValue(node)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   478
                                if write_type != "optional" or attr_value != "":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   479
                                    val = GetComputedValue(attr_type, attr_value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   480
                                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   481
                                    val = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   482
                            elif attr_type.startswith("cls:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   483
                                val = eval("%s()"%attr_type[4:], globals().update(user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   484
                                val.loadXMLTree(node)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   485
                            # Add to content attribute list
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   486
                            if val:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   487
                                self.content.append({"name":name,"value":val})
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   488
                        
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   489
                        # The node child is defined in the list
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   490
                        elif name in dict.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   491
                            attr_type, xml_type, write_type = dict[name]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   492
                            # Extracts the value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   493
                            if attr_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   494
                                attr_value = GetAttributeValue(node)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   495
                                if write_type != "optional" or attr_value != "":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   496
                                    val = GetComputedValue(attr_type.replace("[]",""), attr_value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   497
                                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   498
                                    val = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   499
                            elif attr_type.startswith("cls:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   500
                                val = eval("%s()"%attr_type[4:].replace("[]",""), globals().update(user_classes))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   501
                                val.loadXMLTree(node)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   502
                            # Stock value in attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   503
                            if val:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   504
                                if attr_type.endswith("[]"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   505
                                    getattr(self, name).append(val)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   506
                                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   507
                                    setattr(self, name, val)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   508
        return loadXMLTreeMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   509
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   510
    """
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   511
    Method that generates the method for generating an xml text by following the
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   512
    attributes list defined
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   513
    """
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   514
    def generateGenerateXMLText(cls, bases, dict):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   515
        def generateXMLTextMethod(self, name, indent, extras = {}, derived = False):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   516
            ind1, ind2 = getIndent(indent, name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   517
            if not derived:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   518
                text = ind1 + "<%s"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   519
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   520
                text = ""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   521
            if len(bases) > 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   522
                base_extras = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   523
            if "order" in dict.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   524
                order = dict["order"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   525
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   526
                order = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   527
            if "choice_content" in dict.keys() and "choice_content" not in order:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   528
                order.append("choice_content") 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   529
            if "multichoice_content" in dict.keys() and "multichoice_content" not in order:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   530
                order.append("multichoice_content") 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   531
            size = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   532
            first = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   533
            for attr, value in extras.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   534
                if not first and not self.singleLineAttributes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   535
                    text += "\n%s"%(ind2)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   536
                text += " %s=\"%s\""%(attr, ComputeValue(value))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   537
                first = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   538
            for attr, values in dict.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   539
                if attr in ["order","choice_content","multichoice_content"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   540
                    pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   541
                elif attr in ["enum","limit"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   542
                    if not derived:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   543
                        text += ">%s</%s>\n"%(ComputeValue(self.value),name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   544
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   545
                        text += ComputeValue(self.value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   546
                    return text
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   547
                elif values[1] == "attribute":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   548
                    value = getattr(self, attr, None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   549
                    if values[2] != "optional" or value != None:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   550
                        if not first and not self.singleLineAttributes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   551
                            text += "\n%s"%(ind2)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   552
                        if values[0].startswith("cls"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   553
                            if len(bases) > 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   554
                                base_extras[attr] = value.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   555
                            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   556
                                text += " %s=\"%s\""%(attr, ComputeValue(value.getValue()))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   557
                        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   558
                            if len(bases) > 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   559
                                base_extras[attr] = value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   560
                            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   561
                                text += " %s=\"%s\""%(attr, ComputeValue(value))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   562
                        first = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   563
            if len(bases) > 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   564
                first, new_text = bases[0].generateXMLText(self, name, indent, base_extras, True)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   565
                text += new_text
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   566
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   567
                first = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   568
            ind3, ind4 = getIndent(indent + 1, name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   569
            for attr in order:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   570
                value = getattr(self, attr, None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   571
                if attr == "choice_content":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   572
                    if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   573
                        if first:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   574
                            text += ">\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   575
                            first = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   576
                        value_type = dict[attr][self.content["name"]]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   577
                        if value_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   578
                            if value_type.endswith("[]"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   579
                                for content in self.content["value"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   580
                                    text += ind1 + "<%s>%s</%s>\n"%(self.content["name"], ComputeValue(content), self.content["name"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   581
                            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   582
                                text += ind1 + "<%s>%s</%s>\n"%(self.content["name"], ComputeValue(self.content["value"]), self.content["name"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   583
                        elif value_type.endswith("[]"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   584
                            for content in self.content["value"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   585
                                text += content.generateXMLText(self.content["name"], indent + 1)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   586
                        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   587
                            text += self.content["value"].generateXMLText(self.content["name"], indent + 1)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   588
                elif attr == "multichoice_content":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   589
                    if len(self.content) > 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   590
                        for element in self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   591
                            if first:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   592
                                text += ">\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   593
                                first = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   594
                            value_type = dict[attr][element["name"]]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   595
                            if value_type.startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   596
                                text += ind1 + "<%s>%s</%s>\n"%(element["name"], ComputeValue(element["value"]), element["name"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   597
                            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   598
                                text += element["value"].generateXMLText(element["name"], indent + 1)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   599
                elif dict[attr][2] != "optional" or value != None:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   600
                    if dict[attr][0].endswith("[]"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   601
                        if first and len(value) > 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   602
                            text += ">\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   603
                            first = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   604
                        for element in value:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   605
                            if dict[attr][0].startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   606
                                text += ind3 + "<%s>%s</%s>\n"%(attr, ComputeValue(element), attr)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   607
                            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   608
                                text += element.generateXMLText(attr, indent + 1)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   609
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   610
                        if first:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   611
                            text += ">\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   612
                            first = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   613
                        if dict[attr][0].startswith("bse:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   614
                            text += ind3 + "<%s>%s</%s>\n"%(attr, ComputeValue(value), attr)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   615
                        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   616
                            text += getattr(self, attr).generateXMLText(attr, indent + 1)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   617
            if not derived:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   618
                if first:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   619
                    text += "/>\n"
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   620
                else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   621
                    text += ind1 + "</%s>\n"%(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   622
                return text
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   623
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   624
                return first, text
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   625
        return generateXMLTextMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   626
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   627
    """
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   628
    Methods that generates the different methods for setting and getting the attributes
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   629
    """
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   630
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   631
    def generateInitMethod(cls, bases, dict, user_classes):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   632
        def initMethod(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   633
            for base in bases:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   634
                base.__init__(self)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   635
            for attr, initial in dict.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   636
                setattr(self, attr, eval(initial, globals().update(user_classes)))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   637
        return initMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   638
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   639
    def generateSetMethod(cls, attr, choice_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   640
        def setMethod(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   641
            setattr(self, attr, value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   642
        return setMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   643
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   644
    def generateSetChoiceMethod(cls, attr_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   645
        def setChoiceMethod(self, name, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   646
            self.content = {"name":name,"value":value}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   647
        return setChoiceMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   648
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   649
    def generateSetEnumMethod(cls, enum, attr_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   650
        def setEnumMethod(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   651
            if value in enum:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   652
                self.value = value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   653
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   654
                raise ValueError, "%s is not a valid value. Must be in %s"%(value, str(enum))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   655
        return setEnumMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   656
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   657
    def generateSetLimitMethod(cls, limit, attr_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   658
        def setMethod(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   659
            if "min" in limit and value < limit["min"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   660
                raise ValueError, "%s is not a valid value. Must be greater than %d"%(value, limit["min"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   661
            elif "max" in limit and value > limit["max"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   662
                raise ValueError, "%s is not a valid value. Must be smaller than %d"%(value, limit["max"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   663
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   664
                self.value = value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   665
        return setMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   666
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   667
    def generateGetMethod(cls, attr):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   668
        def getMethod(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   669
            return getattr(self, attr, None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   670
        return getMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   671
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   672
    def generateAddMethod(cls, attr, initial, user_classes):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   673
        def addMethod(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   674
            setattr(self, attr, eval(initial, globals().update(user_classes)))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   675
        return addMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   676
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   677
    def generateDeleteMethod(cls, attr):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   678
        def deleteMethod(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   679
            setattr(self, attr, None)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   680
        return deleteMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   681
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   682
    def generateAppendMethod(cls, attr, attr_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   683
        def appendMethod(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   684
            getattr(self, attr).append(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   685
        return appendMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   686
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   687
    def generateInsertMethod(cls, attr, attr_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   688
        def insertMethod(self, index, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   689
            getattr(self, attr).insert(index, value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   690
        return insertMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   691
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   692
    def generateAppendChoiceMethod(cls, choice_types):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   693
        def appendMethod(self, name, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   694
            self.content.append({"name":name,"value":value})
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   695
        return appendMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   696
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   697
    def generateInsertChoiceMethod(cls, choice_types):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   698
        def insertMethod(self, index, name, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   699
            self.content.insert(index, {"name":name,"value":value})
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   700
        return insertMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   701
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   702
    def generateRemoveMethod(cls, attr):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   703
        def removeMethod(self, index):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   704
            getattr(self, attr).pop(index)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   705
        return removeMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   706
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   707
    def generateCountMethod(cls, attr):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   708
        def countMethod(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   709
            return len(getattr(self, attr))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   710
        return countMethod
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   711
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   712
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   713
Methods that generate the classes
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   714
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   715
def CreateClasses(user_classes, user_types):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   716
    for classname in XMLClasses.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   717
        CreateClass(classname, user_classes, user_types)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   718
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   719
def CreateClass(classname, user_classes, user_types):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   720
    # Checks that classe haven't been generated yet
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   721
    if classname not in user_classes and classname not in user_types and classname in XMLClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   722
        inheritance, attributes = XMLClasses[classname]
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   723
        #print classe, inheritance, attributes
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   724
        dict = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   725
        bases = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   726
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   727
        # If inheritance classes haven't been generated
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   728
        for base in inheritance:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   729
            if base not in user_classes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   730
                CreateClass(base, user_classes, user_types)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   731
            bases.append(user_classes[base])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   732
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   733
        # Checks that all attribute types are available 
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   734
        for attribute, type_attribute in attributes.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   735
            if attribute == "group":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   736
                user_types[classname] = type_attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   737
            elif attribute == "ref":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   738
                user_types[classname] = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   739
                for attr in type_attribute:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   740
                    if attr[4:] not in user_types:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   741
                        CreateClass(attr[4:], user_classes, user_types)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   742
                    user_types[classname].update(user_types[attr[4:]])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   743
            elif attribute in ["choice_content","multichoice_content"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   744
                element_types = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   745
                for attr, value in type_attribute.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   746
                    if attr == "ref":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   747
                        for ref in type_attribute["ref"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   748
                            if ref[4:] not in user_types:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   749
                                CreateClass(ref[4:], user_classes, user_types)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   750
                            element_types.update(user_types[ref[4:]])
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   751
                    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   752
                        element_types[attr] = value
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   753
                dict[attribute] = element_types
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   754
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   755
                dict[attribute] = type_attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   756
                if attribute == "enum":
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   757
                    user_types["%s_enum"%classname] = type_attribute
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   758
                elif attribute not in ["limit", "order"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   759
                    if type_attribute[0].startswith("ppx:"):
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   760
                        type_compute = type_attribute[0][4:].replace("[]","")
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   761
                        if type_compute not in user_classes:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   762
                            CreateClass(type_compute, user_classes, user_types)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   763
        if "group" not in attributes.keys() and "ref" not in attributes.keys():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   764
            cls = MetaClass.__new__(MetaClass, classname, tuple(bases), dict)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   765
            MetaClass.__init__(cls, classname, tuple(bases), dict, user_classes)
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   766
            user_classes[classname] = cls
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   767
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   768
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   769
Methods that print the classes generated
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   770
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   771
def PrintClasses():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   772
    for classname, xmlclass in XMLClasses.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   773
        print "%s : %s\n"%(classname, str(xmlclass))
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   774
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   775
def PrintClassNames():
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   776
    classnames = XMLClasses.keys()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   777
    classnames.sort()
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   778
    for classname in classnames:
93bc4c2cf376 PLCGenerator finished
lbessard
parents:
diff changeset
   779
        print classname