2016-10-17 08:50:25 +02:00
|
|
|
#!/usr/bin/env python
|
2015-12-13 00:01:04 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
import sys
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
|
|
|
|
|
|
tree = ET.parse(sys.argv[1])
|
2016-10-30 18:57:40 +01:00
|
|
|
old_doc = tree.getroot()
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
tree = ET.parse(sys.argv[2])
|
2016-10-30 18:57:40 +01:00
|
|
|
new_doc = tree.getroot()
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
f = file(sys.argv[3], "wb")
|
|
|
|
tab = 0
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
old_classes = {}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
def write_string(_f, text, newline=True):
|
2016-10-30 18:44:57 +01:00
|
|
|
for t in range(tab):
|
|
|
|
_f.write("\t")
|
|
|
|
_f.write(text)
|
2020-03-30 08:28:32 +02:00
|
|
|
if newline:
|
2016-10-30 18:44:57 +01:00
|
|
|
_f.write("\n")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
def escape(ret):
|
2016-11-01 00:24:30 +01:00
|
|
|
ret = ret.replace("&", "&")
|
|
|
|
ret = ret.replace("<", ">")
|
|
|
|
ret = ret.replace(">", "<")
|
|
|
|
ret = ret.replace("'", "'")
|
2020-03-30 08:28:32 +02:00
|
|
|
ret = ret.replace('"', """)
|
2016-10-30 18:44:57 +01:00
|
|
|
return ret
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
def inc_tab():
|
2016-10-30 18:44:57 +01:00
|
|
|
global tab
|
2016-10-30 18:57:40 +01:00
|
|
|
tab += 1
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
def dec_tab():
|
2016-10-30 18:44:57 +01:00
|
|
|
global tab
|
2016-10-30 18:57:40 +01:00
|
|
|
tab -= 1
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, '<?xml version="1.0" encoding="UTF-8" ?>')
|
|
|
|
write_string(f, '<doc version="' + new_doc.attrib["version"] + '">')
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
def get_tag(node, name):
|
|
|
|
tag = ""
|
2020-03-30 08:28:32 +02:00
|
|
|
if name in node.attrib:
|
|
|
|
tag = " " + name + '="' + escape(node.attrib[name]) + '" '
|
2016-10-30 18:44:57 +01:00
|
|
|
return tag
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
def find_method_descr(old_class, name):
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
methods = old_class.find("methods")
|
2020-03-30 08:28:32 +02:00
|
|
|
if methods != None and len(list(methods)) > 0:
|
2016-10-30 18:44:57 +01:00
|
|
|
for m in list(methods):
|
2020-03-30 08:28:32 +02:00
|
|
|
if m.attrib["name"] == name:
|
2016-10-30 18:57:40 +01:00
|
|
|
description = m.find("description")
|
2020-03-30 08:28:32 +02:00
|
|
|
if description != None and description.text.strip() != "":
|
2016-10-30 18:44:57 +01:00
|
|
|
return description.text
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
return None
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
def find_signal_descr(old_class, name):
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
signals = old_class.find("signals")
|
2020-03-30 08:28:32 +02:00
|
|
|
if signals != None and len(list(signals)) > 0:
|
2016-10-30 18:44:57 +01:00
|
|
|
for m in list(signals):
|
2020-03-30 08:28:32 +02:00
|
|
|
if m.attrib["name"] == name:
|
2016-10-30 18:57:40 +01:00
|
|
|
description = m.find("description")
|
2020-03-30 08:28:32 +02:00
|
|
|
if description != None and description.text.strip() != "":
|
2016-10-30 18:44:57 +01:00
|
|
|
return description.text
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
return None
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
def find_constant_descr(old_class, name):
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_class is None:
|
2016-10-30 18:44:57 +01:00
|
|
|
return None
|
|
|
|
constants = old_class.find("constants")
|
2020-03-30 08:28:32 +02:00
|
|
|
if constants != None and len(list(constants)) > 0:
|
2016-10-30 18:44:57 +01:00
|
|
|
for m in list(constants):
|
2020-03-30 08:28:32 +02:00
|
|
|
if m.attrib["name"] == name:
|
|
|
|
if m.text.strip() != "":
|
2016-10-30 18:44:57 +01:00
|
|
|
return m.text
|
|
|
|
return None
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
def write_class(c):
|
2016-10-30 18:44:57 +01:00
|
|
|
class_name = c.attrib["name"]
|
2016-10-30 18:57:40 +01:00
|
|
|
print("Parsing Class: " + class_name)
|
2020-03-30 08:28:32 +02:00
|
|
|
if class_name in old_classes:
|
2016-10-30 18:57:40 +01:00
|
|
|
old_class = old_classes[class_name]
|
2016-10-30 18:44:57 +01:00
|
|
|
else:
|
2016-10-30 18:57:40 +01:00
|
|
|
old_class = None
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
category = get_tag(c, "category")
|
|
|
|
inherits = get_tag(c, "inherits")
|
2020-03-30 08:28:32 +02:00
|
|
|
write_string(f, '<class name="' + class_name + '" ' + category + inherits + ">")
|
2016-10-30 18:44:57 +01:00
|
|
|
inc_tab()
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "<brief_description>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_class != None:
|
2016-10-30 18:57:40 +01:00
|
|
|
old_brief_descr = old_class.find("brief_description")
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_brief_descr != None:
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, escape(old_brief_descr.text.strip()))
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</brief_description>")
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "<description>")
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_class != None:
|
2016-10-30 18:57:40 +01:00
|
|
|
old_descr = old_class.find("description")
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_descr != None:
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, escape(old_descr.text.strip()))
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</description>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
methods = c.find("methods")
|
2020-03-30 08:28:32 +02:00
|
|
|
if methods != None and len(list(methods)) > 0:
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "<methods>")
|
2016-10-30 18:44:57 +01:00
|
|
|
inc_tab()
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for m in list(methods):
|
2016-10-30 18:57:40 +01:00
|
|
|
qualifiers = get_tag(m, "qualifiers")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
write_string(f, '<method name="' + escape(m.attrib["name"]) + '" ' + qualifiers + ">")
|
2016-10-30 18:44:57 +01:00
|
|
|
inc_tab()
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for a in list(m):
|
2020-03-30 08:28:32 +02:00
|
|
|
if a.tag == "return":
|
2016-10-30 18:57:40 +01:00
|
|
|
typ = get_tag(a, "type")
|
2020-03-30 08:28:32 +02:00
|
|
|
write_string(f, "<return" + typ + ">")
|
|
|
|
write_string(f, "</return>")
|
|
|
|
elif a.tag == "argument":
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
default = get_tag(a, "default")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
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:
|
2016-10-30 18:57:40 +01:00
|
|
|
old_method_descr = find_method_descr(old_class, m.attrib["name"])
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_method_descr:
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, escape(escape(old_method_descr.strip())))
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
write_string(f, "</description>")
|
2016-10-30 18:44:57 +01:00
|
|
|
dec_tab()
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</method>")
|
2016-10-30 18:44:57 +01:00
|
|
|
dec_tab()
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</methods>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
signals = c.find("signals")
|
2020-03-30 08:28:32 +02:00
|
|
|
if signals != None and len(list(signals)) > 0:
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "<signals>")
|
2016-10-30 18:44:57 +01:00
|
|
|
inc_tab()
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for m in list(signals):
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, '<signal name="' + escape(m.attrib["name"]) + '">')
|
2016-10-30 18:44:57 +01:00
|
|
|
inc_tab()
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for a in list(m):
|
2020-03-30 08:28:32 +02:00
|
|
|
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:
|
2016-10-30 18:57:40 +01:00
|
|
|
old_signal_descr = find_signal_descr(old_class, m.attrib["name"])
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_signal_descr:
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, escape(old_signal_descr.strip()))
|
2020-03-30 08:28:32 +02:00
|
|
|
write_string(f, "</description>")
|
2016-10-30 18:44:57 +01:00
|
|
|
dec_tab()
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</signal>")
|
2016-10-30 18:44:57 +01:00
|
|
|
dec_tab()
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</signals>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
constants = c.find("constants")
|
2020-03-30 08:28:32 +02:00
|
|
|
if constants != None and len(list(constants)) > 0:
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "<constants>")
|
2016-10-30 18:44:57 +01:00
|
|
|
inc_tab()
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
for m in list(constants):
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, '<constant name="' + escape(m.attrib["name"]) + '" value="' + m.attrib["value"] + '">')
|
|
|
|
old_constant_descr = find_constant_descr(old_class, m.attrib["name"])
|
2020-03-30 08:28:32 +02:00
|
|
|
if old_constant_descr:
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, escape(old_constant_descr.strip()))
|
|
|
|
write_string(f, "</constant>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
dec_tab()
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</constants>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
dec_tab()
|
2016-10-30 18:57:40 +01:00
|
|
|
write_string(f, "</class>")
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
for c in list(old_doc):
|
2016-10-30 18:57:40 +01:00
|
|
|
old_classes[c.attrib["name"]] = c
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
for c in list(new_doc):
|
2016-10-30 18:44:57 +01:00
|
|
|
write_class(c)
|
2020-03-30 08:28:32 +02:00
|
|
|
write_string(f, "</doc>\n")
|