[Formed-commits] r418 - in trunk: . formed/formed formed/formed/model formed/formed/plugins/export
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Nov 8 10:07:46 CET 2010
Author: roland
Date: 2010-11-08 10:07:41 +0100 (Mon, 08 Nov 2010)
New Revision: 418
Modified:
trunk/ChangeLog
trunk/formed/formed/config.py
trunk/formed/formed/model/data.py
trunk/formed/formed/plugins/export/xsd.py
Log:
issue1131: generate XSD for case exports
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-21 08:24:15 UTC (rev 417)
+++ trunk/ChangeLog 2010-11-08 09:07:41 UTC (rev 418)
@@ -1,3 +1,9 @@
+2010-11-08 Roland Geider <roland.geider at intevation.de>
+
+ * formed/formed/model/data.py,
+ formed/formed/plugins/export/xsd.py,
+ formed/formed/config.py: issue1131: generate XSD for case exports
+
2010-10-21 Torsten Irlaender <torsten at intevation.de>
* formed/formed/plugins/export/rules_sh.py: Added new LE-Operator
Modified: trunk/formed/formed/config.py
===================================================================
--- trunk/formed/formed/config.py 2010-10-21 08:24:15 UTC (rev 417)
+++ trunk/formed/formed/config.py 2010-11-08 09:07:41 UTC (rev 418)
@@ -23,7 +23,8 @@
from formed.plugins.export.typemap import ExportAsTypeDict
from formed.plugins.export.diff import ExportDiffAsHTMLFilter
from formed.plugins.export.mode import ModeExportFilter
-from formed.plugins.export.xsd import ExportAsXMLSchema
+from formed.plugins.export.xsd import ExportAsXMLSchema, \
+ ExportAsXMLSchemaExport
from formed.plugins.export.xls import ExportKeyValueTableAsXLS
from formed.plugins.export.rules import ExportRulesAsHTML
@@ -67,6 +68,7 @@
# ExportStoredProcedureFilter(),
# ExportViewsFilter(),
ExportAsXMLSchema(),
+ ExportAsXMLSchemaExport(),
ExportKeyValueTableAsXLS(),
GenerateRequiredRules(),
ExportRulesAsHTML(),
Modified: trunk/formed/formed/model/data.py
===================================================================
--- trunk/formed/formed/model/data.py 2010-10-21 08:24:15 UTC (rev 417)
+++ trunk/formed/formed/model/data.py 2010-11-08 09:07:41 UTC (rev 418)
@@ -60,14 +60,14 @@
class GroupNode(Node):
def __init__(self):
Node.__init__(self)
- self.attributes["repeat"] = ""
+ self.attributes["repeat"] = False
self.attributes["invisible"] = ""
def isRepeat(self):
return self.getAttribute("repeat") and True or False
def setRepeat(self, repeat):
- repeat = repeat and "true" or ""
+ repeat = repeat and True or ""
self.setAttribute("repeat", repeat)
def isInvisible(self):
@@ -109,6 +109,7 @@
self.attributes["min"] = ""
self.attributes["max"] = ""
self.attributes["digest"] = ""
+ self.attributes["repeat"] = True
def getDigest(self):
return self.getAttribute("digest")
Modified: trunk/formed/formed/plugins/export/xsd.py
===================================================================
--- trunk/formed/formed/plugins/export/xsd.py 2010-10-21 08:24:15 UTC (rev 417)
+++ trunk/formed/formed/plugins/export/xsd.py 2010-11-08 09:07:41 UTC (rev 418)
@@ -204,6 +204,7 @@
<xs:element ref="date" minOccurs="0"/>
<xs:element ref="rule" minOccurs="0"/>
<xs:element ref="info" minOccurs="0"/>
+ <xs:element ref="int" minOccurs="0"/>
<xs:element ref="bool" minOccurs="0"/>
<xs:element ref="repeat" minOccurs="0"/>
<xs:element ref="radio-matrix" minOccurs="0"/>
@@ -269,7 +270,7 @@
<xs:simpleType name="version_type">
<xs:restriction base="xs:string">
- <xs:pattern value="[0-2]{1}"/>
+ <xs:pattern value="[0-5]{1}"/>
</xs:restriction>
</xs:simpleType>
@@ -334,7 +335,6 @@
<xs:element name="case">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
- <xs:element ref="master" minOccurs="0"/>
<xs:element ref="group" minOccurs="0"/>
<xs:element ref="repeat_group_type" minOccurs="0"/>
<xs:element ref="tagebuch" minOccurs="0"/>
@@ -345,6 +345,101 @@
</xs:element>
'''
+
+
+XSD_HEADER_EXPORT = \
+'''<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+<xs:element name="cases">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="case" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="version" type="version_type"/>
+ <xs:attribute name="formed-type" type="xs:string"/>
+ </xs:complexType>
+</xs:element>
+
+<xs:element name="case">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="master" minOccurs="0" maxOccurs="1"/>
+ <xs:element ref="repeat_group_type" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element ref="tagebuch" minOccurs="0" maxOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:element>
+
+<xs:simpleType name="version_type">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[0-5]{1}"/>
+ </xs:restriction>
+</xs:simpleType>
+
+<xs:element name="repeat_group_type" abstract="true"/>
+
+<xs:simpleType name="uuid_type">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"/>
+ </xs:restriction>
+</xs:simpleType>
+
+<xs:simpleType name="simple_date_type">
+ <xs:restriction base="xs:date">
+ <xs:pattern value="[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}"/>
+ </xs:restriction>
+</xs:simpleType>
+
+<xs:simpleType name="unknown_integer">
+ <xs:restriction base="xs:integer">
+ <xs:minInclusive value="-999999"/>
+ <xs:maxInclusive value="999999"/>
+ </xs:restriction>
+</xs:simpleType>
+
+<xs:simpleType name="tagebuch-datum_type">
+ <xs:restriction base="xs:dateTime">
+ <xs:pattern value="[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}T[0-9]{2}:[0-9]{2}:[0-9]{2}"/>
+ </xs:restriction>
+</xs:simpleType>
+
+<xs:element name="tagebuch-eintrag">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="1" name="uuid_id" type="uuid_type"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-datum" type="tagebuch-datum_type"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-bearbeiter" type="xs:string"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-art" type="xs:integer"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-sonstiges" type="xs:string"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-notiz" type="xs:string"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-dauer" type="unknown_integer"/>
+ <xs:element minOccurs="0" maxOccurs="1" name="tagebuch-typ" type="xs:integer"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:element>
+
+<xs:element name="tagebuch">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="tagebuch-eintrag" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:element>
+
+
+
+
+<!-- XML schema generated by FormEd
+ %s -->
+'''
+
+
+
+
+
+
+
XSD_FOOTER = \
'''</xs:schema>
'''
@@ -506,6 +601,7 @@
def __init__(self, name, maxOccurs="unbounded"):
self.name = name
self.items = []
+ self.repeat_groups = []
self.maxOccurs = maxOccurs
def dump(self, out):
@@ -517,6 +613,8 @@
for item in self.items:
print >> out, ' <xs:element minOccurs="0" maxOccurs="1" name="%s" type="%s_type"/>' % (
item.name, item.name)
+ for repeat_group in self.repeat_groups:
+ print >> out, ' <xs:element minOccurs="0" maxOccurs="unbounded" name="%s"/>' % (repeat_group.name)
print >> out, ' </xs:sequence>'
print >> out, ' </xs:complexType>'
print >> out, '</xs:element>'
@@ -527,6 +625,9 @@
def appendItem(self, item):
self.items.append(item)
+
+ def appendRepeatGroup(self, rg):
+ self.repeat_groups.append(rg)
class CaseType:
@@ -631,7 +732,7 @@
if not desc: desc = ""
kvs[int(c.getValue())] = desc
except ValueError:
- print >> sys.stderr, "WARNING choice '%s' contains none integer values" % name
+ print >> sys.stderr, "WARNING choice '%s' contains no integer values" % name
return
if not kvs:
@@ -672,7 +773,7 @@
if not desc: desc = ""
kvs[int(c.getValue())] = desc
except ValueError:
- print >> sys.stderr, "WARNING: radio '%s' contains none integer values" % radio.getName()
+ print >> sys.stderr, "WARNING: radio '%s' contains no integer values" % radio.getName()
return
if not kvs:
@@ -698,9 +799,11 @@
@checkMode
def _createGroup(self, group):
repeat = group.isRepeat()
+
if repeat:
- table = TableType(group.getName().replace("rg_", "", 1))
+ table = TableType(group.getName())
self.tableStack.append(table)
+ self.tableStack[0].appendRepeatGroup(table)
self.case.appendTable(table)
for child in group.children:
@@ -738,7 +841,7 @@
FileDialogFilter.__init__(self)
def getMenuName(self):
- return _("Export As XML Schema...")
+ return _("Export As XML Schema (formedtree)...")
def getDescription(self):
return _("Export document as XML schema")
@@ -765,6 +868,23 @@
try:
out = codecs.open(path, "wb", "UTF-8")
out.write(XSD_HEADER % strftime("%a, %Y-%m-%d %H:%M:%S +0000", gmtime()))
+ out.write(XSD_FOOTER)
+ finally:
+ if out:
+ try: out.close()
+ except: pass
+ pass
+
+
+class ExportAsXMLSchemaExport(ExportAsXMLSchema):
+ def getMenuName(self):
+ return _("Export As XML Schema (export)...")
+
+ def doExport(self, path, main, creator):
+ out = None
+ try:
+ out = codecs.open(path, "wb", "UTF-8")
+ out.write(XSD_HEADER_EXPORT % strftime("%a, %Y-%m-%d %H:%M:%S +0000", gmtime()))
case = creator.getCase()
case.dumpTables(out)
creator.dumpEnumerations(out)
@@ -774,5 +894,5 @@
try: out.close()
except: pass
pass
-
+
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
More information about the Formed-commits
mailing list