2016-05-05 19:41:03 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import os
|
2016-05-06 14:19:10 +00:00
|
|
|
import re
|
2016-05-05 19:41:03 +00:00
|
|
|
|
|
|
|
def process_file(fn):
|
|
|
|
mod, ext = os.path.splitext(fn)
|
|
|
|
src = open('../%s' % (fn)).readlines()
|
|
|
|
r = []
|
2016-05-06 14:19:10 +00:00
|
|
|
cls = ''
|
2016-05-05 19:41:03 +00:00
|
|
|
if ext in ['.h', '.c']:
|
|
|
|
for l in src:
|
|
|
|
l = l.rstrip()
|
2016-05-05 20:44:47 +00:00
|
|
|
if l.startswith('/// def '):
|
2016-05-05 19:41:03 +00:00
|
|
|
r.append('``` python')
|
|
|
|
r.append(l[4:])
|
|
|
|
r.append('```')
|
2016-05-05 20:44:47 +00:00
|
|
|
elif l.startswith('/// '):
|
|
|
|
r.append(l[4:])
|
|
|
|
elif l == '///':
|
|
|
|
r.append('')
|
2016-05-05 19:41:03 +00:00
|
|
|
elif ext == '.py':
|
|
|
|
mod = mod[4:].replace('/', '.')
|
2016-05-17 22:58:21 +00:00
|
|
|
if mod.endswith('.__init__'):
|
|
|
|
mod = mod[:-9]
|
2016-05-05 19:41:03 +00:00
|
|
|
for l in src:
|
|
|
|
l = l.rstrip()
|
|
|
|
if l.startswith('def '):
|
|
|
|
r.append('``` python')
|
|
|
|
r.append('def %s.' % mod + l[4:-1])
|
|
|
|
r.append('```')
|
2016-05-06 14:19:10 +00:00
|
|
|
elif l.startswith('### '):
|
|
|
|
r.append(l[4:])
|
|
|
|
elif l.startswith('###'):
|
|
|
|
r.append('')
|
|
|
|
elif l.startswith('class '):
|
|
|
|
cls = re.match('class ([A-Za-z0-9_]*)', l).group(1)
|
|
|
|
elif l.startswith(' def ') and not l.startswith(' def __init__'):
|
|
|
|
r.append('``` python')
|
|
|
|
r.append('def %s.' % cls + l[8:-1])
|
|
|
|
r.append('```')
|
|
|
|
elif l.startswith(' ### '):
|
|
|
|
r.append(l[8:])
|
|
|
|
elif l.startswith(' ###'):
|
|
|
|
r.append('')
|
2016-05-05 19:41:03 +00:00
|
|
|
return r
|
|
|
|
|
|
|
|
def main():
|
|
|
|
tpl = open('api.template.md', 'rt').readlines()
|
|
|
|
f = open('api.md', 'wt')
|
|
|
|
for line in tpl:
|
|
|
|
if line.startswith('@'):
|
|
|
|
for l in process_file(line[1:].strip()):
|
|
|
|
f.write(l + '\n')
|
|
|
|
else:
|
|
|
|
f.write(line)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|