summaryrefslogtreecommitdiff
path: root/doc/tools/doc_merge.py
blob: 6cc7019324523a48513dc9fdb290fdee35859e9b (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import xml.etree.ElementTree as ET


tree = ET.parse(sys.argv[1])
old_doc=tree.getroot()

tree = ET.parse(sys.argv[2])
new_doc=tree.getroot()

f = file(sys.argv[3],"wb")
tab=0

old_classes={}

def write_string(_f, text,newline=True):
	for t in range(tab):
		_f.write("\t")
	_f.write(text)
	if (newline):
		_f.write("\n")

def escape(ret):
	ret=ret.replace("&","&");
	ret=ret.replace("<","&gt;");
	ret=ret.replace(">","&lt;");
	ret=ret.replace("'","&apos;");
	ret=ret.replace("\"","&quot;");
	return ret
	

def inc_tab():
	global tab
	tab+=1

def dec_tab():
	global tab
	tab-=1

write_string(f,'<?xml version="1.0" encoding="UTF-8" ?>')
write_string(f,'<doc version="'+new_doc.attrib["version"]+'">')

def get_tag(node,name):
	tag=""
	if (name in node.attrib):
		tag=' '+name+'="'+escape(node.attrib[name])+'" '
	return tag

def find_method_descr(old_class,name):
	
	methods = old_class.find("methods")    
	if(methods!=None and len(list(methods))>0):
		for m in list(methods):
			if (m.attrib["name"]==name):
				description=m.find("description")
				if (description!=None and description.text.strip()!=""):
					return description.text
	
	return None

def find_signal_descr(old_class,name):
	
	signals = old_class.find("signals")    
	if(signals!=None and len(list(signals))>0):
		for m in list(signals):
			if (m.attrib["name"]==name):
				description=m.find("description")
				if (description!=None and description.text.strip()!=""):
					return description.text
	
	return None

def find_constant_descr(old_class,name):

	if (old_class==None):
		return None	
	constants = old_class.find("constants")    
	if(constants!=None and len(list(constants))>0):
		for m in list(constants):
			if (m.attrib["name"]==name):
				if (m.text.strip()!=""):
					return m.text
	return None

def write_class(c):
	class_name = c.attrib["name"]
	print("Parsing Class: "+class_name)
	if (class_name in old_classes):
		old_class=old_classes[class_name]
	else:
		old_class=None


	category=get_tag(c,"category")
	inherits=get_tag(c,"inherits")
	write_string(f,'<class name="'+class_name+'" '+category+inherits+'>')
	inc_tab()
	
	write_string(f,"<brief_description>")

	if (old_class!=None):
		old_brief_descr=old_class.find("brief_description")
		if (old_brief_descr!=None):
			write_string(f,escape(old_brief_descr.text.strip()))
		
	
	write_string(f,"</brief_description>")
	
	write_string(f,"<description>")
	if (old_class!=None):
		old_descr=old_class.find("description")
		if (old_descr!=None):
			write_string(f,escape(old_descr.text.strip()))
		
	write_string(f,"</description>")

	methods = c.find("methods")    
	if(methods!=None and len(list(methods))>0):

		write_string(f,"<methods>")
		inc_tab()
		
		for m in list(methods):
			qualifiers=get_tag(m,"qualifiers")

			write_string(f,'<method name="'+escape(m.attrib["name"])+'" ' +qualifiers+'>')
			inc_tab()

			for a in list(m):
				if (a.tag=="return"):
					typ=get_tag(a,"type")
					write_string(f,'<return'+typ+'>');
					write_string(f,'</return>');
				elif (a.tag=="argument"):
			
					default=get_tag(a,"default")

					write_string(f,'<argument index="'+a.attrib["index"]+'" name="'+escape(a.attrib["name"])+'" type="'+a.attrib["type"]+'"' +default+'>');
					write_string(f,'</argument>');

			write_string(f,'<description>');
			if (old_class!=None):
				old_method_descr=find_method_descr(old_class,m.attrib["name"])
				if (old_method_descr):
					write_string(f,escape(escape(old_method_descr.strip())))
			
			write_string(f,'</description>');
			dec_tab()					
			write_string(f,"</method>")
		dec_tab()
		write_string(f,"</methods>")

	signals = c.find("signals")    
	if(signals!=None and len(list(signals))>0):

		write_string(f,"<signals>")
		inc_tab()
		
		for m in list(signals):	

			write_string(f,'<signal name="'+escape(m.attrib["name"])+'">')
			inc_tab()

			for a in list(m):
				if (a.tag=="argument"):

					write_string(f,'<argument index="'+a.attrib["index"]+'" name="'+escape(a.attrib["name"])+'" type="'+a.attrib["type"]+'">');
					write_string(f,'</argument>');

			write_string(f,'<description>');
			if (old_class!=None):
				old_signal_descr=find_signal_descr(old_class,m.attrib["name"])
				if (old_signal_descr):
					write_string(f,escape(old_signal_descr.strip()))
			write_string(f,'</description>');
			dec_tab()					
			write_string(f,"</signal>")
		dec_tab()
		write_string(f,"</signals>")

	constants = c.find("constants")    
	if(constants!=None and len(list(constants))>0):

		write_string(f,"<constants>")
		inc_tab()
		
		for m in list(constants):	

			write_string(f,'<constant name="'+escape(m.attrib["name"])+'" value="'+m.attrib["value"]+'">')
			old_constant_descr=find_constant_descr(old_class,m.attrib["name"])
			if (old_constant_descr):
				write_string(f,escape(old_constant_descr.strip()))
			write_string(f,"</constant>")

		dec_tab()
		write_string(f,"</constants>")

	dec_tab()
	write_string(f,"</class>")

for c in list(old_doc):
	old_classes[c.attrib["name"]]=c

for c in list(new_doc):
	write_class(c)
write_string(f,'</doc>\n')