On Tue, Mar 11, 2014 at 10:29:50PM +0800, Jinquan Liu wrote:
> Hi Dave,
>
>
> I'm sorry, seems I'm not using the latest version of vcloud schema.
> After using the latest one, I can find HardwareCustomization node. But
> still cannot find the sub elements under VCloudExtension for 1.xml.
>
>
> [cid:image001.png@01CF3D78.BEF830A0]
>
>
>
> BTW, you can find the latest version here:
>
> [1]http://pubs.vmware.com/vcd-55/topic/com.vmware.vcloud.api.reference.
> doc_55/schema-files.zip
Jinquan,
Thanks for that link.
[Dave Kuhlman wrote, in a previous message]
>
> Also, when I use a generated module to parse and export 1.xml, I see
> that the specific elements LeaseSettingsSection, StartupSection,
> NetworkSection, etc are all exported with the generic name Section.
> I'm working on that.
I believe that I've been able to fix this one.
The HardwareCustomization elements also seem to be preserved in the
exported XML.
Attached is a patch that can be applied to generateDS.py v. 2.12b,
in case you want to try it. However, I've done very little testing
so far; so I'll do more of that next week.
I'll report back next week, after more testing. Hope your weekend
is a good one.
Dave
--
Dave Kuhlman
http://www.davekuhlman.org
diff -r e230b6d9ef12 generateDS.py
--- a/generateDS.py Mon Feb 10 15:25:08 2014 -0800
+++ b/generateDS.py Fri Mar 14 16:05:49 2014 -0700
@@ -177,7 +177,7 @@
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
-VERSION = '2.12b'
+VERSION = '2.12c'
##VERSION##
GenerateProperties = 0
@@ -541,11 +541,7 @@
s1 = '<"%s" SimpleTypeElement instance at 0x%x>' % \
(self.getName(), id(self))
return s1
-
- def __repr__(self):
- s1 = '<"%s" SimpleTypeElement instance at 0x%x>' % \
- (self.getName(), id(self))
- return s1
+ __repr__ = __str__
def resolve_list_type(self):
if self.isListType():
@@ -1376,6 +1372,7 @@
self.inComplexType = 0
self.inNonanonymousComplexType = 0
self.inSequence = 0
+ self.sequenceStack = []
self.inChoice = 1
self.inAttribute = 0
self.attributeGroupLevel = 0
@@ -1449,6 +1446,13 @@
if element.prefix in prefixToNamespaceMap:
element.namespace = prefixToNamespaceMap[element.prefix]
+ if self.sequenceStack:
+ minOccurs, maxOccurs = self.sequenceStack[-1]
+ if 'minOccurs' not in attrs and minOccurs is not None:
+ element.attrs['minOccurs'] = minOccurs
+ if 'maxOccurs' not in attrs and maxOccurs is not None:
+ element.attrs['maxOccurs'] = maxOccurs
+
if not 'type' in attrs.keys() and not 'ref' in attrs.keys():
element.setExplicitDefine(1)
if len(self.stack) == 1:
@@ -1456,6 +1460,7 @@
if 'substitutionGroup' in attrs.keys() and 'name' in attrs.keys():
substituteName = attrs['name']
headName = attrs['substitutionGroup']
+ _, headName = get_prefix_and_value(headName)
if headName not in SubstitutionGroups:
SubstitutionGroups[headName] = []
SubstitutionGroups[headName].append(substituteName)
@@ -1483,6 +1488,8 @@
self.stack.append(element)
elif name == SequenceType:
self.inSequence = 1
+ self.sequenceStack.append(
+ [attrs.get('minOccurs'), attrs.get('maxOccurs')])
elif name == ChoiceType:
self.currentChoice = XschemaElement(attrs)
self.inChoice = 1
@@ -1692,6 +1699,7 @@
self.inComplexType = 0
elif name == SequenceType:
self.inSequence = 0
+ self.sequenceStack.pop()
elif name == ChoiceType:
self.currentChoice = None
self.inChoice = 0
@@ -1826,7 +1834,6 @@
namespace = 'namespace_'
if child.prefix and 'ref' in child.attrs:
namespace = "'%s:'" % child.prefix
-
s1 = "%s outfile.write('<%%s%s>%%s</%%s%s>%%s' %% " \
"(%s, self.gds_format_string(quote_xml(self.%s)." \
"encode(ExternalEncoding), input_name='%s'), " \
@@ -2542,6 +2549,8 @@
wrt(" eol_ = '\\n'\n")
wrt(' else:\n')
wrt(" eol_ = ''\n")
+ wrt(" if self.original_tagname_ is not None:\n")
+ wrt(" name_ = self.original_tagname_\n")
wrt(' showIndent(outfile, level, pretty_print)\n')
wrt(" outfile.write('<%s%s%s' % (namespace_, name_, "
"namespacedef_ and ' ' + namespacedef_ or '', ))\n")
@@ -3479,7 +3488,7 @@
if headChild.getMaxOccurs() > 1:
substitutionGroup = child.getAttrs().get('substitutionGroup')
if substitutionGroup is not None:
- name = substitutionGroup
+ _, name = get_prefix_and_value(substitutionGroup)
else:
name = mappedName
s1 = " self.%s.append(obj_)\n" % (name, )
@@ -3491,6 +3500,7 @@
name = headName
s1 = " self.%s = obj_\n" % (mappedName, )
wrt(s1)
+ wrt(" obj_.original_tagname_ = '%s'\n" % (origName, ))
#
# If this child is defined in a simpleType, then generate
# a validator method.
@@ -3794,6 +3804,11 @@
childCount = countChildren(element, 0)
s2 = buildCtorArgs_multilevel(element, childCount)
wrt(' def __init__(self%s):\n' % s2)
+ # Save the original tag name. This is needed when there is a
+ # xs:substitutionGroup and we later (e.g. during export) do not know
+ # which member of the xs:substitutionGroup this specific element
+ # came from.
+ wrt(' self.original_tagname_ = None\n')
parentName, parent = getParentName(element)
if parentName:
if parentName in AlreadyGenerated:
@@ -3836,9 +3851,7 @@
pythonType = SchemaToPythonTypeMap.get(attrDef.getType())
attrVal = "_cast(%s, %s)" % (pythonType, name, )
wrt(' self.%s = %s\n' % (name, attrVal, ))
- member = 1
# Generate member initializers in ctor.
- member = 0
for child in element.getChildren():
name = cleanupName(child.getCleanName())
logging.debug("Constructor child: %s" % name)
@@ -3900,22 +3913,16 @@
wrt(' self.%s = %s\n' % (name, name))
else:
wrt(' self.%s = %s\n' % (name, name))
- member = 1
eltype = element.getType()
if (element.getSimpleContent() or
element.isMixed() or
eltype in SimpleTypeDict or
CurrentNamespacePrefix + eltype in OtherSimpleTypes):
wrt(' self.valueOf_ = valueOf_\n')
- member = 1
if element.getAnyAttribute():
wrt(' self.anyAttributes_ = {}\n')
- member = 1
if element.getExtended():
wrt(' self.extensiontype_ = extensiontype_\n')
- member = 1
- if not member:
- wrt(' pass\n')
if element.isMixed():
wrt(MixedCtorInitializers)
# end generateCtor
@@ -4190,8 +4197,7 @@
# If this element is an extension (has a base) and the base has
# not been generated, then postpone it.
if parentName:
- if (parentName not in AlreadyGenerated and
- parentName not in SimpleTypeDict):
+ if parentName not in AlreadyGenerated:
PostponedExtensions.append(element)
return
if mapName(element.getName()) in AlreadyGenerated:
@@ -4917,8 +4923,8 @@
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootTag = '%(name)s'
- rootClass = %(prefix)s%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = %(prefix)s%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -4937,8 +4943,8 @@
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootTag = '%(name)s'
- rootClass = %(prefix)s%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = %(prefix)s%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -4962,7 +4968,7 @@
roots = get_root_tag(rootNode)
rootClass = roots[1]
if rootClass is None:
- rootClass = %(prefix)s%(root)s
+ rootClass = %(prefix)s%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -4980,8 +4986,8 @@
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootTag = '%(name)s'
- rootClass = %(prefix)s%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = %(prefix)s%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -4989,7 +4995,7 @@
#silence# if not silence:
#silence# sys.stdout.write('#from %(module_name)s import *\\n\\n')
#silence# sys.stdout.write('import %(module_name)s as model_\\n\\n')
-#silence# sys.stdout.write('rootObj = model_.rootTag(\\n')
+#silence# sys.stdout.write('rootObj = model_.rootClass(\\n')
#silence# rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
#silence# sys.stdout.write(')\\n')
return rootObj
@@ -5024,19 +5030,32 @@
exportDictLine += "}\n\n\n"
outfile.write(exportDictLine)
children = root.getChildren()
+ rootClass = None
if children:
name = RootElement or children[0].getName()
elType = cleanupName(children[0].getType())
if RootElement:
- rootElement = RootElement
+ roots = RootElement.split('|')
+ if len(roots) > 1:
+ rootElement = roots[0]
+ rootClass = roots[1]
+ else:
+ rootElement = roots[0]
else:
rootElement = elType
else:
name = ''
if RootElement:
- rootElement = RootElement
+ roots = RootElement.split('|')
+ if len(roots) > 1:
+ rootElement = roots[0]
+ rootClass = roots[1]
+ else:
+ rootElement = roots[0]
else:
rootElement = ''
+ if rootClass is None:
+ rootClass = rootElement
if Namespacedef:
namespace = Namespacedef
elif Targetnamespace:
@@ -5053,7 +5072,8 @@
'name': name,
'cleanname': cleanupName(name),
'module_name': os.path.splitext(os.path.basename(outfile.name))[0],
- 'root': rootElement,
+ 'rootElement': rootElement,
+ 'rootClass': rootClass,
'namespacedef': namespace,
}
s1 = TEMPLATE_MAIN % params
@@ -5355,8 +5375,8 @@
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootTag = '%(name)s'
- rootClass = supermod.%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = supermod.%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -5375,8 +5395,8 @@
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootTag = '%(name)s'
- rootClass = supermod.%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = supermod.%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -5399,8 +5419,8 @@
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootTag = '%(name)s'
- rootClass = supermod.%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = supermod.%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -5416,10 +5436,10 @@
def parseLiteral(inFilename, silence=False):
doc = parsexml_(inFilename)
rootNode = doc.getroot()
- roots = get_root_tag(rootNode)
- rootClass = roots[1]
+ rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
- rootClass = supermod.%(root)s
+ rootTag = '%(rootElement)s'
+ rootClass = supermod.%(rootClass)s
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
@@ -5427,8 +5447,8 @@
#silence# if not silence:
#silence# sys.stdout.write('#from %(super)s import *\\n\\n')
#silence# sys.stdout.write('import %(super)s as model_\\n\\n')
-#silence# sys.stdout.write('rootObj = model_.%(cleanname)s(\\n')
-#silence# rootObj.exportLiteral(sys.stdout, 0, name_="%(cleanname)s")
+#silence# sys.stdout.write('rootObj = model_.rootClass(\\n')
+#silence# rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
#silence# sys.stdout.write(')\\n')
return rootObj
@@ -5518,7 +5538,6 @@
namespace = 'xmlns:%s="%s"' % (
NamespacesDict[Targetnamespace].rstrip(':'),
Targetnamespace, )
-
return namespace
@@ -5559,19 +5578,32 @@
generateSubclass(
wrt, element, prefix, xmlbehavior, behaviors, baseUrl)
children = root.getChildren()
+ rootClass = None
if children:
name = children[0].getName()
elType = cleanupName(children[0].getType())
if RootElement:
- rootElement = RootElement
+ roots = RootElement.split('|')
+ if len(roots) > 1:
+ rootElement = roots[0]
+ rootClass = roots[1]
+ else:
+ rootElement = roots[0]
else:
rootElement = elType
else:
name = ''
if RootElement:
- rootElement = RootElement
+ roots = RootElement.split('|')
+ if len(roots) > 1:
+ rootElement = roots[0]
+ rootClass = roots[1]
+ else:
+ rootElement = roots[0]
else:
rootElement = ''
+ if rootClass is None:
+ rootClass = rootElement
if Namespacedef:
namespace = Namespacedef
elif Targetnamespace:
@@ -5589,7 +5621,9 @@
'cleanname': cleanupName(name),
'module_name': os.path.splitext(
os.path.basename(subclassFilename))[0],
- 'root': rootElement,
+ 'root': root,
+ 'rootElement': rootElement,
+ 'rootClass': rootClass,
'namespacedef': namespace,
'super': superModule,
}
@@ -5653,7 +5687,6 @@
type))
for subChild in child.getChildren():
childStack.append(subChild)
-
return externalImports
@@ -5674,9 +5707,7 @@
outfile = os.tmpfile()
wrt = outfile.write
processed = []
-
externalImports = getImportsForExternalXsds(root)
-
generateHeader(wrt, prefix, externalImports)
#generateSimpleTypes(outfile, prefix, SimpleTypeDict)
DelayedElements = []
@@ -5767,7 +5798,6 @@
def get_prefix_and_value(val):
if ':' in val:
return val.split(':')
-
return None, val
@@ -5865,13 +5895,11 @@
infile = sys.stdin
else:
infile = open(xschemaFileName, 'r')
-
if SingleFileOutput:
parser = make_parser()
dh = XschemaHandler()
## parser.setDocumentHandler(dh)
parser.setContentHandler(dh)
-
if processIncludes:
import process_includes
outfile = StringIO.StringIO()
@@ -5885,7 +5913,6 @@
parser.parse(infile)
root = dh.getRoot()
root.annotate()
-
## print '-' * 60
## root.show(sys.stdout, 0)
## print '-' * 60
@@ -5906,7 +5933,6 @@
outfile = open(outfileName, "a")
outfile.write(exportLine)
outfile.close()
-
else:
import process_includes
rootPaths = process_includes.get_all_root_file_paths(
@@ -5915,23 +5941,30 @@
roots = []
rootInfos = []
for path in rootPaths:
- rootFile = open(path, 'r')
-
+ if path.startswith('http:') or path.startswith('ftp:'):
+ try:
+ urlfile = urllib2.urlopen(path)
+ content = urlfile.read()
+ urlfile.close()
+ rootFile = StringIO.StringIO()
+ rootFile.write(content)
+ rootFile.seek(0)
+ except urllib2.HTTPError:
+ msg = "Can't find file %s." % (path, )
+ raise IOError(msg)
+ else:
+ rootFile = open(path, 'r')
parser = make_parser()
dh = XschemaHandler()
parser.setContentHandler(dh)
parser.parse(rootFile)
-
root = dh.getRoot()
roots.append(root)
rootFile.close()
-
for root in roots:
root.annotate()
-
moduleName = None
modulePath = None
-
# use the first root element to set
# up the module name and path
for child in root.getChildren():
@@ -5941,33 +5974,26 @@
# no need to create a module for
# xs: types
continue
-
# convert to lower camel case if needed.
if "-" in typeName:
tokens = typeName.split("-")
typeName = ''.join([t.title() for t in tokens])
-
moduleName = typeName[0].lower() + typeName[1:]
-
modulePath = (
OutputDirectory +
os.sep + moduleName +
ModuleSuffix + ".py")
-
fqnToModuleNameMap[child.getFullyQualifiedType()] = \
moduleName
fqnToModuleNameMap[child.getFullyQualifiedName()] = \
moduleName
break
-
rootInfos.append((root, modulePath))
-
for root, modulePath in rootInfos:
if modulePath:
generate(
modulePath, subclassFilename, behaviorFilename,
prefix, root, superModule)
-
# Generate __all__. When using the parser as a module
# it is useful
# to isolate important classes from internal ones. This way one
@@ -6249,7 +6275,6 @@
OutputDirectory = option[1]
elif option[0] == "--module-suffix":
ModuleSuffix = option[1]
-
if showVersion:
print 'generateDS.py version %s' % VERSION
sys.exit(0)
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users