dabo Commit
Revision 2317
Date: 2006-10-08 16:23:06 -0700 (Sun, 08 Oct 2006)
Author: ed

Changed:
U   trunk/dabo/lib/DesignerXmlConverter.py

Log:
Fixed a bug that was ignoring the code associated with saved classes. 
Refactored the importing of source XML files to avoid code duplication. 


Diff:
Modified: trunk/dabo/lib/DesignerXmlConverter.py
===================================================================
--- trunk/dabo/lib/DesignerXmlConverter.py      2006-10-07 02:48:28 UTC (rev 
2316)
+++ trunk/dabo/lib/DesignerXmlConverter.py      2006-10-08 23:23:06 UTC (rev 
2317)
@@ -45,6 +45,31 @@
                represents. You can pass the cdxml as either a file path, 
                a file object, or xml text.
                """
+               # Import the XML source
+               dct = self.importSrc(src)       
+               # Parse the XML and create the class definition text
+               self.createClassText(dct)
+               # Write the code file
+               txt = self._import + LINESEP + self._codeFileText
+               open(self._codeFileName, "w").write(txt)
+               # Add the imports to the main file, too.
+               self.classText = self.classText % (self._import + LINESEP,)
+               
+               ## For debugging. This creates a copy of the generated code
+               ## so that you can help determine any problems.
+               open("CLASSTEXT.py", "w").write(self.classText)
+
+               compClass = compile(self.classText, "", "exec")
+               nmSpace = {}
+               exec compClass in nmSpace
+               return nmSpace[self.mainClassName]
+
+       
+       def importSrc(self, src):
+               """This will read in an XML source. The parameter can be a 
+               file path, an open file object, or the raw XML. It will look for
+               a matching code file and, if found, import that code.
+               """
                if isinstance(src, file):
                        xml = src.read()
                        self._srcFile = src.name
@@ -54,7 +79,7 @@
                                self._srcFile = src
                        else:
                                xml = src
-                               self._srcFile = None
+                               self._srcFile = os.getcwd()
                dct = xtd.xmltodict(xml)
 
                codePth = "%s-code.py" % os.path.splitext(src)[0]
@@ -63,25 +88,9 @@
                        desUtil.addCodeToClassDict(dct, codeDict)
                except StandardError, e:
                        print "Failed to parse code file:", e
+               return dct
 
-               # Parse the XML and create the class definition text
-               self.createClassText(dct)
-               # Write the code file
-               txt = self._import + LINESEP + self._codeFileText
-               open(self._codeFileName, "w").write(txt)
-               # Add the imports to the main file, too.
-               self.classText = self.classText % (self._import + LINESEP,)
-               
-               ## For debugging. This creates a copy of the generated code
-               ## so that you can help determine any problems.
-               open("CLASSTEXT.py", "w").write(self.classText)
 
-               compClass = compile(self.classText, "", "exec")
-               nmSpace = {}
-               exec compClass in nmSpace
-               return nmSpace[self.mainClassName]
-
-       
        def createClassText(self, dct, addImports=True, specList=[]):
                # 'self.classText' will contain the generated code
                self.classText = ""
@@ -436,8 +445,7 @@
                for this class. 
                """
                conv = DesignerXmlConverter()
-               xml = open(pth).read()
-               xmlDict = xtd.xmltodict(xml)
+               xmlDict = conv.importSrc(pth)
                conv.createClassText(xmlDict, addImports=False, 
specList=specList)
                self.innerClassText += conv.classText + (2 * LINESEP)
                self.innerClassNames.append(conv.mainClassName)




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to