msmith - in flumotion/trunk: . flumotion/admin/gtk flumotion/common

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Tue Dec 4 18:29:01 CET 2007


Author: msmith
Date: Tue Dec  4 18:28:50 2007
New Revision: 5971

Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/flumotion/admin/gtk/client.py
   flumotion/trunk/flumotion/common/fxml.py
Log:
    * flumotion/admin/gtk/client.py:
      Don't use automated pretty-printer, didn't output very nicely.
    * flumotion/common/fxml.py:
      Make the sxml outputter pretty-print in a nice custom way.
      Fixes #801



Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Tue Dec  4 18:28:50 2007
@@ -1,3 +1,11 @@
+2007-12-04  Michael Smith <msmith at fluendo.com>
+
+	* flumotion/admin/gtk/client.py:
+	  Don't use automated pretty-printer, didn't output very nicely.
+	* flumotion/common/fxml.py:
+	  Make the sxml outputter pretty-print in a nice custom way.
+	  Fixes #801
+
 2007-12-04  Andy Wingo  <wingo at pobox.com>
 
 	* flumotion/component/combiners/switch/switch.py

Modified: flumotion/trunk/flumotion/admin/gtk/client.py
==============================================================================
--- flumotion/trunk/flumotion/admin/gtk/client.py	(original)
+++ flumotion/trunk/flumotion/admin/gtk/client.py	Tue Dec  4 18:28:50 2007
@@ -31,8 +31,6 @@
 from twisted.internet import reactor
 from twisted.internet.defer import maybeDeferred
 from zope.interface import implements
-from xml.dom.ext import PrettyPrint
-from xml.dom.ext.reader.Sax import FromXml
 
 from flumotion.admin.admin import AdminModel
 from flumotion.admin import connections
@@ -881,8 +879,7 @@
 
             if not file_exists:
                 f = open(name, 'w')
-                doc = FromXml(conf_xml.encode("utf-16"))
-                PrettyPrint(doc, f)
+                f.write(conf_xml)
                 f.close()
                 chooser.destroy()
 

Modified: flumotion/trunk/flumotion/common/fxml.py
==============================================================================
--- flumotion/trunk/flumotion/common/fxml.py	(original)
+++ flumotion/trunk/flumotion/common/fxml.py	Tue Dec  4 18:28:50 2007
@@ -218,14 +218,12 @@
             raise self.parserError('failed to parse %s as %s: %s', node,
                                    type, log.getExceptionMessage(e))
 
-
 # this xml generation thingie is from a friday project, woo
-def sxml2unicode(expr):
+def sxml2unicode(expr, indent=0):
     if not isinstance(expr, list):
         return escape(unicode(expr))
     operator = expr[0]
-    args = [sxml2unicode(arg) for arg in expr[1:]]
-    return unicode(operator(args))
+    return unicode(operator(indent, expr[1:]))
 
 def _trans(k):
     table = {'klass': 'class'}
@@ -242,8 +240,16 @@
                               ''.join([' %s=%s' % (_trans(k), quoteattr(v))
                                        for k, v in kw.items()]))
             post = '</%s>' % (_trans(attr),)
-            def render(args):
-                return pre + '\n'.join(args) + post
+            def render(indent, args):
+                ind = ' '*indent
+                if len(args) == 0:
+                    return ind + pre[:-1] + ' />'
+                elif len(args) == 1 and not isinstance(args[0], list):
+                    return ind + pre + sxml2unicode(args[0]) + post
+                else:
+                    return (ind + pre + '\n' + '\n'.join(map(
+                        lambda x: sxml2unicode(x,indent+2), args)) + 
+                        '\n' + ind + post)
             render.__name__ = pre
             return render
         tag.__name__ = attr 


More information about the flumotion-commit mailing list