Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / tools / python / makeTree.py
1 import sys
2 import pyatspi
3 import uuid
4
5 from xml.dom import minidom
6
7 INTERFACES = [
8 "Accessible",
9 "Desktop",
10 "Image",
11 "StreamableContent",
12 "Action",
13 "Document",
14 "Table",
15 "Application",
16 "EditableText",
17 "MatchRule",
18 "Text",
19 "Collection",
20 "Hyperlink",
21 "Value",
22 "Component",
23 "Hypertext",
24 "Selection",
25 ]
26
27 def getChild(accessible, i):
28         try:
29                 child = accessible.getChildAtIndex(i)
30         except LookupError:
31                 child = None
32         return child
33
34 def createNode(accessible, parentRef, parentElement):
35         e = minidom.Element("accessible")
36         reference = '/' + str(uuid.uuid4()).replace('-', '')
37
38         e.attributes["reference"] = reference
39         e.attributes["parent"] = parentRef
40         e.attributes["name"] = accessible.name
41         e.attributes["role"] = str(accessible.getRole())
42         e.attributes["description"] = accessible.description
43
44         for i in INTERFACES:
45                 query = getattr(accessible, "query" + i)
46                 try:
47                         query()
48                         itf = minidom.Element("interface")
49                         itf.attributes["name"] = i
50                         e.appendChild(itf)
51                 except NotImplementedError:
52                         pass
53                 except LookupError:
54                         pass
55
56         try:
57                 count = accessible.childCount
58         except LookupError:
59                 count = 0
60         
61         for i in range(count):
62                 child = getChild(accessible, i)
63                 if child is not None:
64                         createNode(child, reference, e)
65
66         parentElement.appendChild(e)
67
68 def main(argv):
69         filename = argv[1]
70         doc = minidom.Document()
71         desk = pyatspi.Registry.getDesktop(0)
72         createNode(desk, '/', doc)
73         
74         file = open(filename, 'w')
75         file.write(doc.toprettyxml())
76         file.close()
77
78 if __name__ == "__main__":
79         sys.exit(main(sys.argv))