commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8283 - in grc/trunk: scripts src/grc


From: jblum
Subject: [Commit-gnuradio] r8283 - in grc/trunk: scripts src/grc
Date: Sat, 26 Apr 2008 12:15:08 -0600 (MDT)

Author: jblum
Date: 2008-04-26 12:15:07 -0600 (Sat, 26 Apr 2008)
New Revision: 8283

Modified:
   grc/trunk/scripts/grc
   grc/trunk/src/grc/ParseXML.py
Log:
removed xml.dom.ext references, created custom xml pretty print

Modified: grc/trunk/scripts/grc
===================================================================
--- grc/trunk/scripts/grc       2008-04-26 16:59:47 UTC (rev 8282)
+++ grc/trunk/scripts/grc       2008-04-26 18:15:07 UTC (rev 8283)
@@ -38,7 +38,7 @@
        (options, args) = parser.parse_args()   
        #"test" import modules that this program will use
        error = False
-       for module in ('pygtk', 'wx', 'numpy', 'xml.dom.minidom', 
'xml.dom.ext', 'gnuradio', 'gnuradio.gr.hier_block2', 'Cheetah'):
+       for module in ('pygtk', 'wx', 'numpy', 'xml.dom.minidom', 'gnuradio', 
'gnuradio.gr.hier_block2', 'Cheetah'):
                try: __import__(module)         
                except ImportError: #print error
                        error = True

Modified: grc/trunk/src/grc/ParseXML.py
===================================================================
--- grc/trunk/src/grc/ParseXML.py       2008-04-26 16:59:47 UTC (rev 8282)
+++ grc/trunk/src/grc/ParseXML.py       2008-04-26 18:15:07 UTC (rev 8283)
@@ -21,7 +21,6 @@
 address@hidden Josh Blum
 
 import xml.dom.minidom
-import xml.dom.ext
 from xml.parsers.xmlproc import xmlval
 from xml.parsers.xmlproc import xmlproc
 from xml.parsers.xmlproc import xmldtd
@@ -101,23 +100,29 @@
        @return the xml doc
        """
        doc = xml.dom.minidom.Document()
-       doc.appendChild(_to_xml(nested_data, doc))
+       doc.appendChild(_to_xml(nested_data, doc, 1))
        return doc
        
-def _to_xml(nested_data, doc):
+def _to_xml(nested_data, doc, level):
        """!
        Recursivly parse the nested data into xml doc format.
        @param nested_data the nested data
        @param the xml document class for creating nodes
+       @param level the nesting level
        @return the xml doc filled with child nodes
        """     
        assert(len(nested_data) == 1)
        tag_name, value = nested_data.items()[0]
        child = doc.createElementNS(None, tag_name)
        if type(value) == type(odict()):        
+               child.appendChild(doc.createTextNode("\n"))
                for key, elems in value.iteritems():
                        if type(elems) != type(list()): elems = [elems]
-                       for elem in elems: 
child.appendChild(_to_xml(odict({key: elem}), doc))
+                       for elem in elems:                              
+                               
child.appendChild(doc.createTextNode("\t"*level))
+                               child.appendChild(_to_xml(odict({key: elem}), 
doc, level + 1))
+                               child.appendChild(doc.createTextNode("\n"))
+               child.appendChild(doc.createTextNode("\t"*(level-1)))
        elif value: child.appendChild(doc.createTextNode(value))
        return child
 
@@ -127,7 +132,7 @@
        @param doc the xml doc
        @param file_path the destination xml-file
        """ 
-       xml.dom.ext.PrettyPrint(doc, open(file_path, 'w'))
+       open(file_path, 'w').write(doc.toxml())
        
 def from_file(file_path):
        """!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]