dogtail r388 - in trunk: . dogtail



Author: zcerza
Date: Tue Feb 19 21:00:30 2008
New Revision: 388
URL: http://svn.gnome.org/viewvc/dogtail?rev=388&view=rev

Log:
* dogtail/tree.py, dogtail/dump.py: Allow tree.Node.dump() to output
to a file instead of stdout.


Modified:
   trunk/ChangeLog
   trunk/dogtail/dump.py
   trunk/dogtail/tree.py

Modified: trunk/dogtail/dump.py
==============================================================================
--- trunk/dogtail/dump.py	(original)
+++ trunk/dogtail/dump.py	Tue Feb 19 21:00:30 2008
@@ -4,18 +4,23 @@
 __author__ = "Zack Cerza <zcerza redhat com>"
 
 spacer = ' '
-def plain (node, depth = 0):
+def plain (node, fileName = None):
     """
     Plain-text dump. The hierarchy is represented through indentation.
-    The default indentation string is a single space, ' ', but can be changed.
     """
-    print spacer*(depth) + str (node)
-    try:
+    def crawl(node, depth):
+        dump(node, depth)
         for action in node.actions.values():
-            print spacer*(depth + 1) + str (action)
-    except AttributeError: pass
-    try:
+            dump(action, depth + 1)
         for child in node.children:
-            plain (child, depth + 1)
-    except AttributeError: pass
+            crawl(child, depth + 1)
+
+    def dumpFile(item, depth): _file.write(spacer*depth + str(item) + '\n')
+    def dumpStdOut(item, depth): print spacer*depth + str(item)
+    if fileName:
+        dump = dumpFile
+        _file = file(fileName, 'w')
+    else: dump = dumpStdOut
+    
+    crawl(node, 0)
 

Modified: trunk/dogtail/tree.py
==============================================================================
--- trunk/dogtail/tree.py	(original)
+++ trunk/dogtail/tree.py	Tue Feb 19 21:00:30 2008
@@ -588,10 +588,10 @@
         assert isinstance(pred, predicate.Predicate)
         return pred.satisfiedByNode(self)
 
-    def dump (self, type = 'plain'):
+    def dump (self, type = 'plain', fileName = None):
         import dump
         dumper = getattr (dump, type)
-        dumper (self)
+        dumper (self, fileName)
 
     def getAbsoluteSearchPath(self):
         """



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