~ubuntu-branches/ubuntu/utopic/dogtail/utopic

« back to all changes in this revision

Viewing changes to dogtail/dump.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-12-21 13:33:47 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20061221133347-xo9jg11afp5plcka
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
# Anyway, I'd *love* to be able to unregister this signal handler.
8
8
import signal, sys
9
9
def signalHandler (signal, frame):
10
 
        sys.exit(0)
 
10
    sys.exit(0)
11
11
signal.signal(signal.SIGINT, signalHandler)
12
12
 
13
13
spacer = ' '
14
14
def plain (node, depth = 0):
15
 
        """
16
 
        Plain-text dump. The hierarchy is represented through indentation.
17
 
        The default indentation string is a single space, ' ', but can be changed.
18
 
        """
19
 
        print spacer*(depth) + str (node)
20
 
        try:
21
 
                for action in node.actions:
22
 
                        print spacer*(depth + 1) + str (action)
23
 
        except AttributeError: pass
24
 
        try:
25
 
                for child in node.children:
26
 
                        plain (child, depth + 1)
27
 
        except AttributeError: pass
 
15
    """
 
16
    Plain-text dump. The hierarchy is represented through indentation.
 
17
    The default indentation string is a single space, ' ', but can be changed.
 
18
    """
 
19
    print spacer*(depth) + str (node)
 
20
    try:
 
21
        for action in node.actions:
 
22
            print spacer*(depth + 1) + str (action)
 
23
    except AttributeError: pass
 
24
    try:
 
25
        for child in node.children:
 
26
            plain (child, depth + 1)
 
27
    except AttributeError: pass
28
28
 
29
29
def xml (node):
30
 
        try: import cElementTree as ElementTree
31
 
        except ImportError: from elementtree import ElementTree
32
 
        def buildElementTree (parentElement, node):
33
 
                element = ElementTree.SubElement(parentElement, 'node')
34
 
                name = ElementTree.SubElement(element, 'name')
35
 
                name.text = node.name
36
 
                roleName = ElementTree.SubElement(element, 'roleName')
37
 
                roleName.text = node.roleName
38
 
                description = ElementTree.SubElement(element, 'description')
39
 
                description.text = node.description
40
 
                try:
41
 
                        text = ElementTree.SubElement(element, 'text')
42
 
                        text.text = node.text
43
 
                except AttributeError: pass
44
 
                
45
 
                try:
46
 
                        for action in node.actions:
47
 
                                actionElement = ElementTree.SubElement(element, 'action')
48
 
                                name = ElementTree.SubElement(actionElement, 'name')
49
 
                                name.text = action.name
50
 
                                description = ElementTree.SubElement(actionElement, 'description')
51
 
                                description.text = action.description
52
 
                                keyBinding = ElementTree.SubElement(actionElement, 'keyBinding')
53
 
                                keyBinding.text = action.keyBinding
54
 
                except AttributeError: pass     
55
 
                
56
 
                try:
57
 
                        for child in node.children:
58
 
                                buildElementTree(element, child)
59
 
                except AttributeError: pass
60
 
        root = ElementTree.Element('node')
61
 
        element = root
62
 
        buildElementTree(root, node)
63
 
        tree = ElementTree.ElementTree(root)
64
 
        ElementTree.dump(tree)
65
 
                
66
 
 
 
30
    try: import cElementTree as ElementTree
 
31
    except ImportError: from elementtree import ElementTree
 
32
    def buildElementTree (parentElement, node):
 
33
        element = ElementTree.SubElement(parentElement, 'node')
 
34
        name = ElementTree.SubElement(element, 'name')
 
35
        name.text = node.name
 
36
        roleName = ElementTree.SubElement(element, 'roleName')
 
37
        roleName.text = node.roleName
 
38
        description = ElementTree.SubElement(element, 'description')
 
39
        description.text = node.description
 
40
        try:
 
41
            text = ElementTree.SubElement(element, 'text')
 
42
            text.text = node.text
 
43
        except AttributeError: pass
 
44
 
 
45
        try:
 
46
            for action in node.actions:
 
47
                actionElement = ElementTree.SubElement(element, 'action')
 
48
                name = ElementTree.SubElement(actionElement, 'name')
 
49
                name.text = action.name
 
50
                description = ElementTree.SubElement(actionElement, 'description')
 
51
                description.text = action.description
 
52
                keyBinding = ElementTree.SubElement(actionElement, 'keyBinding')
 
53
                keyBinding.text = action.keyBinding
 
54
        except AttributeError: pass
 
55
 
 
56
        try:
 
57
            for child in node.children:
 
58
                buildElementTree(element, child)
 
59
        except AttributeError: pass
 
60
    root = ElementTree.Element('node')
 
61
    element = root
 
62
    buildElementTree(root, node)
 
63
    tree = ElementTree.ElementTree(root)
 
64
    ElementTree.dump(tree)