Commit 50f2b2e7 authored by Dave Kuhlman's avatar Dave Kuhlman

Fixes to examples under directory Demos/

parent 533c97e6
This directory contains a small example of the use of
generateDS.py. It contains the following:
- outline.xsd -- The XML Schema file used to generate Python data
representation classes.
- outline.py -- This file was generated by running:
python generateDS.py -o outline.py outline.xsd
- outline_extended.py -- This file was produced by generating a
subclass file, then adding methods that show the outline in a
brief format. It was initially generated by running:
python generateDS.py -s outline_extended.py outline.xsd
and then was edited to add the extensions.
- outline.xml -- A sample data file used the test the generated
Python code. Run either of the following:
python outline.py outline.xml
python outline_extended.py outline.xml
Dave Kuhlman
dkuhlman@rexx.com
http://www.rexx.com/~dkuhlman
Outline -- a demo for generateDS.py
=====================================
This directory contains a small example of the use of `generateDS.py`.
It demonstrates the use of a generated subclass file to add extended
behavior to the code generated by `generateDS.py`. It contains the
following:
- outline.xsd -- The XML Schema file used to generate Python data
representation classes.
- outline.py -- This file was generated by using the "-o" command
line option for `generateDS.py`.
python ../../generateDS.py -o outline.py outline.xsd
- outline_extended.py -- This file was produced by generating a
subclass file. See use of "-s" and "--super" command line
options, above. Then we add methods that show the outline in a
brief format. The file was originally produced with the following
command, *but* you might want to save the extensions in that file
before regenerating it:
python ../../generateDS.py -o outline.py -s outline_extended.py --super="outline" outline.xsd
- outline.xml -- A sample data file used to test the generated
Python code. Run either of the following:
python outline.py outline.xml
python outline_extended.py outline.xml
.. vim:ft=rst:
This diff is collapsed.
......@@ -6,17 +6,17 @@
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="child" maxOccurs="unbounded" type="node"/>
<xs:element name="child" maxOccurs="unbounded" type="nodeType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="node">
<xs:element name="nodeType">
<xs:complexType>
<xs:sequence>
<xs:element name="label" type="xs:string"/>
<xs:element name="text" type="xs:string"/>
<xs:element name="child" type="node" maxOccurs="unbounded"/>
<xs:element name="child" type="nodeType" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="hidden" type="xs:string" />
</xs:complexType>
......
#!/usr/bin/env python
#
# Generated Mon Aug 18 17:12:21 2003 by generateDS.py.
# Generated Thu Jul 19 13:39:44 2018 by generateDS.py version 2.29.17.
# Python 2.7.15 |Anaconda custom (64-bit)| (default, May 1 2018, 23:32:55) [GCC 7.2.0]
#
# Command line options:
# ('-o', 'outline.py')
# ('-s', 'outline_extended.py')
# ('--super', 'outline')
#
# Command line arguments:
# outline.xsd
#
# Command line:
# ../../generateDS.py -o "outline.py" -s "outline_extended.py" --super="outline" outline.xsd
#
# Current working directory (os.getcwd()):
# Outline
#
import sys
from xml.dom import minidom
from lxml import etree as etree_
import outline as supermod
def parsexml_(infile, parser=None, **kwargs):
if parser is None:
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
parser = etree_.ETCompatXMLParser()
doc = etree_.parse(infile, parser=parser, **kwargs)
return doc
#
# Globals
#
ExternalEncoding = ''
#
# Support/utility functions.
#
......@@ -18,59 +47,147 @@ def showIndent(outfile, level):
outfile.write(' ')
#
# Data representation classes
#
class outlineSub(supermod.outline):
def __init__(self, name='', description='', children=None):
supermod.outline.__init__(self, name, description, children)
def __init__(self, name=None, description=None, child=None):
super(outlineSub, self).__init__(name, description, child, )
def show(self, outfile, level):
outfile.write('==========================================\n')
outfile.write('Outline name: %s\n' % self.name)
outfile.write('Outline description: %s\n' % self.description)
outfile.write('==========================================\n')
for child in self.children:
for child in self.child:
child.show(outfile, level)
outfile.write('==========================================\n')
supermod.outline.subclass = outlineSub
# end class outlineSub
class nodeSub(supermod.node):
def __init__(self, label='', text='', children=None, hidden=''):
supermod.node.__init__(self, label, text, children, hidden)
class nodeTypeSub(supermod.nodeType):
def __init__(self, hidden=None, label=None, text=None, child=None):
super(nodeTypeSub, self).__init__(hidden, label, text, child, )
def show(self, outfile, level):
if self.hidden == 't':
return
showIndent(outfile, level)
outfile.write('%s. %s\n' % (self.label, self.text))
for child in self.children:
for child in self.child:
child.show(outfile, level + 1)
supermod.node.subclass = nodeSub
# end class nodeSub
supermod.nodeType.subclass = nodeTypeSub
# end class nodeTypeSub
def get_root_tag(node):
tag = supermod.Tag_pattern_.match(node.tag).groups()[-1]
rootClass = None
rootClass = supermod.GDSClassesMapping.get(tag)
if rootClass is None and hasattr(supermod, tag):
rootClass = getattr(supermod, tag)
return tag, rootClass
def parse(inFilename, silence=False):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'outline'
rootClass = supermod.outline
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
if not silence:
sys.stdout.write('<?xml version="1.0" ?>\n')
rootObj.export(
sys.stdout, 0, name_=rootTag,
namespacedef_='',
pretty_print=True)
return rootObj
def parse(inFilename):
doc = minidom.parse(inFilename)
rootNode = doc.childNodes[0]
rootObj = supermod.outline.factory()
def parseEtree(inFilename, silence=False):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'outline'
rootClass = supermod.outline
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
mapping = {}
rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping)
reverse_mapping = rootObj.gds_reverse_node_mapping(mapping)
if not silence:
content = etree_.tostring(
rootElement, pretty_print=True,
xml_declaration=True, encoding="utf-8")
sys.stdout.write(content)
sys.stdout.write('\n')
return rootObj, rootElement, mapping, reverse_mapping
def parseString(inString, silence=False):
if sys.version_info.major == 2:
from StringIO import StringIO
else:
from io import BytesIO as StringIO
parser = None
doc = parsexml_(StringIO(inString), parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'outline'
rootClass = supermod.outline
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
if not silence:
sys.stdout.write('<?xml version="1.0" ?>\n')
rootObj.export(
sys.stdout, 0, name_=rootTag,
namespacedef_='')
return rootObj
def parseString(inString):
doc = minidom.parseString(inString)
rootNode = doc.childNodes[0]
rootObj = supermod.outline.factory()
def parseLiteral(inFilename, silence=False):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'outline'
rootClass = supermod.outline
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
if not silence:
sys.stdout.write('#from outline import *\n\n')
sys.stdout.write('import outline as model_\n\n')
sys.stdout.write('rootObj = model_.rootClass(\n')
rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
sys.stdout.write(')\n')
return rootObj
USAGE_TEXT = """
Usage: python outline_extended.py <infilename>
Usage: python ???.py <infilename>
"""
def usage():
print USAGE_TEXT
sys.exit(-1)
print(USAGE_TEXT)
sys.exit(1)
def main():
......@@ -79,13 +196,9 @@ def main():
usage()
infilename = args[0]
root = parse(infilename)
sys.stdout.write('<?xml version="1.0" ?>\n')
root.show(sys.stdout, 0)
if __name__ == '__main__':
#import pdb; pdb.set_trace()
main()
#import pdb
#pdb.run('main()')
This directory contains a simple example of the use of
generateDS.py. The following files are provided:
- people_7.xsd -- This is the XML Schema file used to generate
peoplesup.py and peoplesub.py
- peoplesup.py and peoplesub.py -- Generated from people.xsd.
peoplesup.py contains the superclasses; peoplesub.py contains
the generated subclasses. They were generated by running the
following:
$ generateDS.py --session=a7.session
Or:
$ ../../generateDS.py -f -m \
--namespacedef='xmlns:pl="http://kuhlman.com/people.xsd"' \
--super=peoplesup -o peoplesup.py -s peoplesub.py \
--member-specs=dict \
people_7.xsd
Or, if you want validator bodies:
$ ../../generateDS.py -f -m \
--validator-bodies=Validators \
--namespacedef='xmlns:pl="http://kuhlman.com/people.xsd"' \
--super=peoplesup -o peoplesup.py -s peoplesub.py \
--member-specs=dict \
people_7.xsd
Notice that because the validator bodies sub-directory
Validators contains a file named percent.py, you should see that
the method validate_percent in class person in the generated
file peoplesup.py as been filled in with a body.
- people_7.xml -- A data file used to test peoplesup.py and
peoplesub.py. Run the following to test it:
$ python peoplesup.py people_7.xml
Or,
$ python peoplesub.py people_7.xml
Note that you might need to edit the subclass file
(peoplesub.py), changing the import supermod statement, and run
that modified file. This modification is possibly not needed if
you used the --super= flag.
======================
A generateDS.py demo
======================
Running the example
=====================
This directory contains a simple example of the use of
generateDS.py.
On Linux, you can run a test with the shell script
`run-full-test.sh` as follows:
$ ./run-full-test.sh test
The above shell script will use `people.xsd` to produce `testsup.py`
(with the "-o" command line option) and `testsub.py` (with the "-s"
command line option). It then runs the generated subclass
(`testsub.py`) file to parse and export `people.xml`.
Generating validator bodies
=============================
You can generate code containing validator bodies by running
`run-full-test-validators.sh`. After running that shell script, the
code in `Validators/FlowType.py` will have been copying into the
method `validate_FlowType`. (`Validators/percent.py` is not used in
this example.)
.. vim:ft=rst:
<?xml version="1.0" ?>
<session>
<input_schema>people.xsd</input_schema>
<output_superclass>peoplesup.py</output_superclass>
<output_subclass>peoplesub.py</output_subclass>
<force>true</force>
<prefix></prefix>
<namespace_prefix></namespace_prefix>
<empty_namespace_prefix>false</empty_namespace_prefix>
<behavior_filename></behavior_filename>
<properties>true</properties>
<subclass_suffix></subclass_suffix>
<root_element></root_element>
<superclass_module>peoplesup</superclass_module>
<auto_super>true</auto_super>
<old_getters_setters>false</old_getters_setters>
<validator_bodies></validator_bodies>
<user_methods></user_methods>
<no_dates>false</no_dates>
<no_versions>false</no_versions>
<no_process_includes>false</no_process_includes>
<silence>false</silence>
<namespace_defs>xmlns:pl="http://kuhlman.com/people.xsd"</namespace_defs>
<external_encoding></external_encoding>
<member_specs>dict</member_specs>
</session>
<?xml version="1.0"?>
<!DOCTYPE catalog
PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
prefer="public">
<public publicId="http://www.generateds.com/people-part1"
uri="schemas/people-part1.xsd"/>
</catalog>
This diff is collapsed.
This diff is collapsed.
#!/bin/sh -x
if [ $# -ne 1 ]; then
echo
echo Usage: run-ful-test-validators.sh out_file_name_stem
echo
exit 0
fi
python ../../generateDS.py -f -m \
--validator-bodies=Validators \
--use-old-simpletype-validators \
--namespacedef='xmlns:pl="http://kuhlman.com/people.xsd"' \
--super=$1sup -o $1sup.py -s $1sub.py \
--member-specs=dict \
-m \
--export="write etree literal" \
-c people_catalog.xml \
people.xsd
python $1sub.py people.xml 2> $1_warnings.txt | tee $1.xml
......@@ -2,16 +2,18 @@
if [ $# -ne 1 ]; then
echo
echo Usage: run_full_test out_file_name_stem
echo Usage: run-ful-test.sh out_file_name_stem
echo
exit 0
fi
../../generateDS.py -f -m \
python ../../generateDS.py -f -m \
--namespacedef='xmlns:pl="http://kuhlman.com/people.xsd"' \
--super=$1sup -o $1sup.py -s $1sub.py \
--member-specs=dict \
-m \
--export="write etree literal" \
-c people_catalog.xml \
people.xsd
python $1sub.py people.xml | tee $1.xml
python $1sub.py people.xml 2> $1_warnings.txt | tee $1.xml
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="airplane">
<xs:complexContent>
<xs:extension base="vehicleType" >
<xs:sequence>
<xs:element name="pilotname" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
============
XMLBehaviors
============
*Under repair*
*Notice:* The example in this directory is currently not working.
This sub-directory contains a simple example of the use of
the XMLBehavior capability of generateDS.py.
......@@ -41,3 +46,4 @@ Files of interest in the directory/example are:
instance documents. It was used by generateDS.py to generate
xmlbehavior.py and xmlbehavior_sub.py.
.. vim:ft=rst:
#!/bin/bash
if [ $# -ne 1 ]; then
echo
echo Usage: run-test.sh out_file_name_stem
echo
exit 0
fi
python ../../generateDS.py \
-f \
-o $1sup.py \
-s $1sub.py \
--super="$1sup" \
-b xmlbehavior_po.xml \
po.xsd
......@@ -4,6 +4,7 @@
# Generated Wed Jun 30 10:34:05 2004 by generateDS.py.
#
from __future__ import print_function
import sys
import getopt
from xml.dom import minidom
......@@ -562,7 +563,7 @@ class SaxXml_behaviorHandler(handler.ContentHandler):
self.locator = locator
def showError(self, msg):
print '*** (showError):', msg
print('*** (showError):', msg)
sys.exit(-1)
def startElement(self, name, attrs):
......@@ -736,7 +737,7 @@ Options:
"""
def usage():
print USAGE_TEXT
print(USAGE_TEXT)
sys.exit(-1)
......
......@@ -4,6 +4,7 @@
# Generated Tue Jun 29 16:14:16 2004 by generateDS.py.
#
from __future__ import print_function
import sys
from xml.dom import minidom
from xml.sax import handler, make_parser
......@@ -150,7 +151,7 @@ Usage: python ???.py <infilename>
"""
def usage():
print USAGE_TEXT
print(USAGE_TEXT)
sys.exit(-1)
......
......@@ -141,6 +141,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Change history
--------------
Version 2.29.18 (07/19/2018)
- Fixes to the example code underneath `Demos/`. Thanks to Witold
Jarzynka for reporting this.
Version 2.29.17 (07/11/2018)
- Merged pull request that generates enum classes for each simpleType.
......@@ -149,7 +154,6 @@ Version 2.29.17 (07/11/2018)
ForeignKey declarations. (2) Added relative import (dot) to
generated admin.py.
Version 2.29.16 (06/21/2018)
- Added dependencies to ``setup.py``. Thanks to Laszlo for this
......
......@@ -225,7 +225,7 @@ _log = logging.getLogger(__name__)
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
VERSION = '2.29.17'
VERSION = '2.29.18'
##VERSION##
BaseStrTypes = six.string_types
......
......@@ -12,7 +12,7 @@ generateDS -- Generate Data Structures from XML Schema
.. version
:revision: 2.29.17
:revision: 2.29.18
.. version
......
......@@ -12,7 +12,7 @@ GenerateDS GUI Notes
.. version
:revision: 2.29.17
:revision: 2.29.18
.. version
......
......@@ -41,7 +41,7 @@ from libgenerateDS.gui import generateds_gui_session
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
VERSION = '2.29.17'
VERSION = '2.29.18'
##VERSION##
......
......@@ -8,7 +8,7 @@ How to package a generateDS.py generated library
.. version
:revision: 2.29.17
:revision: 2.29.18
.. version
......