[rhmessaging-commits] rhmessaging commits: r2276 - in mgmt/trunk/mint: python/mint and 1 other directory.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Mon Aug 11 17:13:51 EDT 2008
Author: nunofsantos
Date: 2008-08-11 17:13:51 -0400 (Mon, 11 Aug 2008)
New Revision: 2276
Modified:
mgmt/trunk/mint/Makefile
mgmt/trunk/mint/python/mint/schemaparser.py
Log:
parser handles multiple xml schema files specified in SCHEMA_XML env var
Modified: mgmt/trunk/mint/Makefile
===================================================================
--- mgmt/trunk/mint/Makefile 2008-08-11 18:15:24 UTC (rev 2275)
+++ mgmt/trunk/mint/Makefile 2008-08-11 21:13:51 UTC (rev 2276)
@@ -29,9 +29,8 @@
schema: schema-python schema-sql
schema-python:
- @if [ -z "$$MINT_SCHEMA_XML" ]; then echo "MINT_SCHEMA_XML is not set"; exit 1; fi
- python python/mint/schemaparser.py ${MINT_SCHEMA_XML} python/mint/schema.py ${dsn}
- @if [ -z "$$STORE_SCHEMA_XML" ]; then echo "Warning: STORE_SCHEMA_XML is not set, skipping store schema generation"; else echo "python python/mint/schemaparser.py ${STORE_SCHEMA_XML} python/mint/schema.py ${dsn} append"; python python/mint/schemaparser.py ${STORE_SCHEMA_XML} python/mint/schema.py ${dsn} append; fi
+ @if [ -z "$$SCHEMA_XML" ]; then echo "SCHEMA_XML is not set. SCHEMA_XML should contain a space-separated list of XML schema files to be parsed."; exit 1; fi
+ python python/mint/schemaparser.py python/mint/schema.py ${dsn} ${SCHEMA_XML}
schema-sql:
sqlobject-admin sql -m mint -m mint.schema -c ${dsn} | sed -e '1,2d' > sql/schema.sql
Modified: mgmt/trunk/mint/python/mint/schemaparser.py
===================================================================
--- mgmt/trunk/mint/python/mint/schemaparser.py 2008-08-11 18:15:24 UTC (rev 2275)
+++ mgmt/trunk/mint/python/mint/schemaparser.py 2008-08-11 21:13:51 UTC (rev 2276)
@@ -4,25 +4,15 @@
class SchemaParser:
"""parses broker XML schema"""
- def __init__(self, xmlSchemaPath, pythonFilePath, dsn, append=""):
- self.xmlSchemaPath = xmlSchemaPath
+ def __init__(self, pythonFilePath, dsn, xmlFilePaths):
self.pythonFilePath = pythonFilePath
self.dsn = dsn
+ self.xmlFilePaths = xmlFilePaths
self.style = MixedCaseUnderscoreStyle()
self.additionalPythonOutput = ""
self.currentClass = ""
self.pythonOutput = ""
self.finalPythonOutput = ""
- if (append == ""):
- self.pythonOutput += "import mint\n"
- self.pythonOutput += "from sqlobject import *\n"
- self.pythonOutput += "from datetime import datetime\n"
- self.finalPythonOutput += "\nclassToSchemaNameMap = dict()\n"
- self.finalPythonOutput += "schemaNameToClassMap = dict()\n"
- self.append = False
- else:
- self.pythonOutput += "\n\n"
- self.append = True
# mapping between xml schema types and database column types
# see xml/MintTypes.xml
self.dataTypesMap = dict()
@@ -180,31 +170,35 @@
self.currentClass = ""
def generateCode(self):
- if (self.append):
- fileFlag = "a"
- else:
- fileFlag = "w"
- outputFile = open(self.pythonFilePath, fileFlag)
- schema = mllib.xml_parse(self.xmlSchemaPath)
- classes = schema.query["schema/class"]
- for cls in classes:
- self.startClass(cls["@name"])
- self.generateClassAttribs(cls["@name"], cls.query["property"])
- for elem in cls.query["method"]:
- self.generateMethod(elem)
- self.endClass()
- self.startClass(cls["@name"], stats=True)
- self.generateClassAttribs(cls["@name"], cls.query["statistic"])
- self.endClass()
+
+ self.pythonOutput += "import mint\n"
+ self.pythonOutput += "from sqlobject import *\n"
+ self.pythonOutput += "from datetime import datetime\n"
+ self.finalPythonOutput += "\nclassToSchemaNameMap = dict()\n"
+ self.finalPythonOutput += "schemaNameToClassMap = dict()\n"
+ outputFile = open(self.pythonFilePath, "w")
+ for xmlFile in self.xmlFilePaths:
+ schema = mllib.xml_parse(xmlFile)
+ classes = schema.query["schema/class"]
+ for cls in classes:
+ self.startClass(cls["@name"])
+ self.generateClassAttribs(cls["@name"], cls.query["property"])
+ for elem in cls.query["method"]:
+ self.generateMethod(elem)
+ self.endClass()
+ self.startClass(cls["@name"], stats=True)
+ self.generateClassAttribs(cls["@name"], cls.query["statistic"])
+ self.endClass()
+ self.pythonOutput += "\n\n"
outputFile.write(self.pythonOutput + self.finalPythonOutput)
outputFile.close()
if __name__ == "__main__":
import sys
- if len(sys.argv) not in (4,5):
- print "Usage: schemaparser.py INPUT-XML-SCHEMA OUTPUT-PYTHON-FILE DSN [APPEND]"
+ if len(sys.argv) < 3:
+ print "Usage: schemaparser.py OUTPUT-PYTHON-FILE DSN INPUT-XML-SCHEMA [INPUT-XML-SCHEMA]*"
sys.exit(1)
else:
- parser = SchemaParser(*sys.argv[1:])
+ parser = SchemaParser(sys.argv[1], sys.argv[2], sys.argv[3:])
parser.generateCode()
More information about the rhmessaging-commits
mailing list