Author: nunofsantos
Date: 2008-09-02 17:14:21 -0400 (Tue, 02 Sep 2008)
New Revision: 2386
Modified:
mgmt/trunk/mint/python/mint/schemaparser.py
Log:
support groups in xml schema
Modified: mgmt/trunk/mint/python/mint/schemaparser.py
===================================================================
--- mgmt/trunk/mint/python/mint/schemaparser.py 2008-09-02 20:09:10 UTC (rev 2385)
+++ mgmt/trunk/mint/python/mint/schemaparser.py 2008-09-02 21:14:21 UTC (rev 2386)
@@ -13,6 +13,7 @@
self.currentClass = ""
self.pythonOutput = ""
self.finalPythonOutput = ""
+ self.groups = dict()
# mapping between xml schema types and database column types
# see xml/MintTypes.xml
self.dataTypesMap = dict()
@@ -115,9 +116,7 @@
elif (elem["@type"] == "lstr" or elem["@type"] ==
"ftable"):
args += "length=4000"
self.generateAttrib(self.attrNameFromDbColumn(elemName),
self.dataTypesMap[elem["@type"]], args)
-
self.pythonOutput += "\n"
- self.pythonOutput += " classInfos = dict() # brokerId => classInfo\n"
def startClass(self, schemaName, stats=False):
schemaName = self.renameReservedWord(schemaName)
@@ -145,6 +144,7 @@
self.generateForeignKeyAttrib("statsPrev", statsPythonName)
self.finalPythonOutput += "classToSchemaNameMap['%s'] =
'%s'\n" % (pythonName, schemaName)
self.finalPythonOutput += "schemaNameToClassMap['%s'] = %s\n" %
(schemaName, pythonName)
+ self.pythonOutput += " classInfos = dict() # brokerId => classInfo\n"
def generateMethod(self, elem):
if (elem["@desc"] != None):
@@ -185,15 +185,28 @@
outputFile = open(self.pythonFilePath, "w")
for xmlFile in self.xmlFilePaths:
schema = mllib.xml_parse(xmlFile)
+ # parse groups and store their structure as is
+ groups = schema.query["schema/group"]
+ for grp in groups:
+ self.groups[grp["@name"]] = grp.query["property"],
grp.query["statistic"]
+
+ # parse class definitions
classes = schema.query["schema/class"]
for cls in classes:
self.startClass(cls["@name"])
self.generateClassAttribs(cls["@name"],
cls.query["property"])
+ # generate properties attribs from any groups included in this class
+ for clsGroup in cls.query["group"]:
+ self.generateClassAttribs(cls["@name"],
self.groups[clsGroup["@name"]][0])
for elem in cls.query["method"]:
self.generateMethod(elem)
self.endClass()
+
self.startClass(cls["@name"], stats=True)
self.generateClassAttribs(cls["@name"],
cls.query["statistic"])
+ # generate statistics attribs from any groups included in this class
+ for clsGroup in cls.query["group"]:
+ self.generateClassAttribs(cls["@name"],
self.groups[clsGroup["@name"]][1])
self.endClass()
self.pythonOutput += "\n\n"
outputFile.write(self.pythonOutput + self.finalPythonOutput)
Show replies by date