> 1. Some elements in "1.xml" are not serialized. e.g.
>    <NetworkConfigSection>, <LeaseSettingsSection>, etc.
> 
> The parent <VApp> contains elements of Sections. But in my xml, they
> may be occurred as elements like <NetworkConfigSection> whose type
> is the inherited from Section_Type. So the name may not be
> "Section".

I believe that I finally figured this one.  I apologize for being
slow.  The problem was that NetworkConfigSection,
LeaseSettingsSection, etc used a substitution group:

    substitutionGroup="ovf:Section"

But, that substitutionGroup had a namespace prefix, which meant that
generateDS.py was not recognizing it correctly.

I do not have any of your instance documents, so I cannot really
test the generated module.  The code looks good to me; I can
successfully import the module in Python; and it does not break any
of my unit tests.

I've attached a patch that fixes this, I believe.  The attached
patch also includes the fixes I sent you earlier.  I believe that
that if you apply this patch file to a a copy of generateDS.py that
already has the previsous patches, it will ignore those already
applied changes.  If not, perhaps you can start with an unchanged
version from v. 2.12b.

There are actually two patch files, but I do not believe that the
one for process_includes.py affects what you are doing.

[from your most recent email message]

> Hi Dave,
> Thank you for your patch. I have tested for vcloud xsd files. I believe it
> resolves the 2 issues. But just got a new issue, well... actually I found
> it last week but forgot to report... I replaced all xsd localtions to
> local path in xsd's, but still failed to generate pys files for vcloud.
> The new issue may be caused by the circular references.
> Below is the cmd I used:
> c:\Python27\Scripts>python.exe generateDS.py -f --one-file-per-xsd
> --output-directory="c:\tmp" <my
> folder>\schema-files\1.5\schemas\extension\vmwextensions.xsd
> But I only got 2 output .py files and "Task.py" is empty. And the cmd
> never exit...
> I looked into these xsds and found the circular references as below:
> Task.xsd:
>         <xs:include schemaLocation="entity.xsd"/>
>       <xs:include schemaLocation="common.xsd"/>
> Entity.xsd
>         <xs:include schemaLocation="common.xsd"/>
>       <xs:include schemaLocation="task.xsd"/>
> Common.xsd
>         <xs:include schemaLocation="task.xsd"/>
> 

Jinquan,

I'll look into this one tomorrow.  In the meantime, here is what
I've tried.

Here is the command I used:

    $ generateDS.py -f -o tmp07sup.py -s tmp07sub.py --super=tmp07sup
      Vcloud_schema/1.5/schemas/extension/vmwextensions.xsd

The above successfully generated two modules: tmp07sup.py and
tmp07sub.py.

Then I tried the one-per way:

    $ generateDS.py -f --one-file-per-xsd --output-directory=OnePer
    --module-suffix=Version1
    Vcloud_schema/1.5/schemas/extension/vmwextensions.xsd

You are right.  That seems to go into some kind of loop.  It seems
strange that it does not loop or stall when I generate the usual
modules without the one-per options.  Perhaps that is a clue.  I'll
look into it tomorrow.  In the meantime, I'm guessing that there is
some class that it cannot generate because the superclass of that
class has not been generated, and it's looping until the superclass
is generated.  I'll report back when I learn more.

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     Thu Mar 06 13:57:18 2014 -0800
@@ -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():
@@ -1456,6 +1452,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)
@@ -3479,7 +3476,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, )
@@ -4190,8 +4187,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:
@@ -5518,7 +5514,6 @@
             namespace = 'xmlns:%s="%s"' % (
                 NamespacesDict[Targetnamespace].rstrip(':'),
                 Targetnamespace, )
-
     return namespace
 
 
@@ -5653,7 +5648,6 @@
                                             type))
             for subChild in child.getChildren():
                 childStack.append(subChild)
-
     return externalImports
 
 
@@ -5674,9 +5668,7 @@
         outfile = os.tmpfile()
     wrt = outfile.write
     processed = []
-
     externalImports = getImportsForExternalXsds(root)
-
     generateHeader(wrt, prefix, externalImports)
     #generateSimpleTypes(outfile, prefix, SimpleTypeDict)
     DelayedElements = []
@@ -5767,7 +5759,6 @@
 def get_prefix_and_value(val):
     if ':' in val:
         return val.split(':')
-
     return None, val
 
 
@@ -5865,13 +5856,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 +5874,6 @@
         parser.parse(infile)
         root = dh.getRoot()
         root.annotate()
-
 ##     print '-' * 60
 ##     root.show(sys.stdout, 0)
 ##     print '-' * 60
@@ -5906,7 +5894,6 @@
             outfile = open(outfileName, "a")
             outfile.write(exportLine)
             outfile.close()
-
     else:
         import process_includes
         rootPaths = process_includes.get_all_root_file_paths(
@@ -5915,23 +5902,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 +5935,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 +6236,6 @@
             OutputDirectory = option[1]
         elif option[0] == "--module-suffix":
             ModuleSuffix = option[1]
-
     if showVersion:
         print 'generateDS.py version %s' % VERSION
         sys.exit(0)
diff -r e230b6d9ef12 process_includes.py
--- a/process_includes.py       Mon Feb 10 15:25:08 2014 -0800
+++ b/process_includes.py       Thu Mar 06 13:57:35 2014 -0800
@@ -30,7 +30,7 @@
 # Do not modify the following VERSION comments.
 # Used by updateversion.py.
 ##VERSION##
-VERSION = '2.12b'
+VERSION = '2.12c'
 ##VERSION##
 
 CatalogDict = {}
@@ -527,6 +527,10 @@
         "-f", "--force", action="store_true",
         dest="force", default=False,
         help="force overwrite without asking")
+    parser.add_option(
+        "--fix-type-names", action="store",
+        dest="fixtypenames", default=None,
+        help="Fix up (replace) complex type names.")
     (options, args) = parser.parse_args()
     if len(args) == 2:
         inpath = args[0]
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to