blob: 3756820a5109a501b87a73f9d43963166ecb2b3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
"""Utility functions for 'dumping' trees of Node objects.
Author: Zack Cerza <zcerza@redhat.com>"""
__author__ = "Zack Cerza <zcerza@redhat.com>"
from __builtin__ import file
spacer = ' '
def plain(node, fileName=None):
"""
Plain-text dump. The hierarchy is represented through indentation.
"""
def crawl(node, depth):
dump(node, depth)
for action in node.actions.values():
dump(action, depth + 1)
for child in node.children:
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)
|