forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkygen.py
111 lines (95 loc) · 3.01 KB
/
markygen.py
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
#! python3
"""
This is a terrible script that generates markdown from doxygen output.
"""
import argparse
from lxml import etree as et
from mako.template import Template
class DoxyObject(object):
def __init__(self, xml):
self._xml = xml
self.brief = self._get('briefdescription/para')
self.desc = self._get('detaileddescription/para')
self.refid = xml.get('refid')
self.id = xml.get('id')
def _get(self, xpath):
try:
return self._xml.xpath(xpath)[0].text
except IndexError:
return ''
class Parameter(DoxyObject):
def __init__(self, xml):
super().__init__(xml)
self.name = self._get('parameternamelist/parametername')
self.desc = self._get('parameterdescription/para')
class Function(DoxyObject):
def __init__(self, xml):
super().__init__(xml)
self.visibility = xml.get('prot')
self.is_static = xml.get('static') == 'yes'
self.is_const = xml.get('const') == 'yes'
self.is_explicit = xml.get('explicit') == 'yes'
self.is_inline = xml.get('inline') == 'yes'
self.is_virtual = xml.get('virtual') == 'virtual'
self.name = self._get('name')
self.type = self._get('type')
self.type = self._get_type()
self.argsstr = self._get('argsstring')
try:
self.params = [
Parameter(p)
for p in xml.xpath(
'detaileddescription/para/parameterlist[@kind="param"]')[0]
]
except IndexError:
self.params = []
try:
self.tparams = [
Parameter(p)
for p in xml.xpath(
'detaileddescription/para/parameterlist[@kind="templateparam"]')[
0]
]
except IndexError:
self.tparams = []
try:
self.exceptions = [
Parameter(p)
for p in xml.xpath(
'detaileddescription/para/parameterlist[@kind="exception"]')[0]
]
except IndexError:
self.exceptions = []
self.note = self._get(
'detaileddescription/para/simplesect[@kind="note"]/para')
self.returns = self._get(
'detaileddescription/para/simplesect[@kind="return"]/para')
def _get_type(self):
try:
type_name = self._xml.xpath('type/ref')[0].text
except IndexError:
type_name = self._xml.xpath('type')[0].text
return type_name
class Class(DoxyObject):
def __init__(self, xml):
super().__init__(xml)
self.name = self._get('compoundname')
self.includes = self._get('includes')
self.functions = [
Function(f)
for f in xml.xpath(
'sectiondef[@kind="public-func"]/memberdef[@kind="function"]')
]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('input')
parser.add_argument('template')
parser.add_argument('output')
args = parser.parse_args()
tree = et.parse(args.input)
classes = [Class(i) for i in tree.xpath('//compounddef[@kind="class"]')]
with open(args.template) as t:
tdata = t.read()
mytemplate = Template(tdata)
with open(args.output, 'w') as f:
f.write(mytemplate.render(classes=classes))