forked from sio2project/oioioi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgendoc.py
55 lines (39 loc) · 1.29 KB
/
gendoc.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
# Generate documentation script
# This script traverses the main oioioi directory, making an entry
# in modules.rst file for each oioioi module.
from __future__ import print_function
import os
import sys
sys.path.append("../")
import oioioi
sections_suff = '../rst/source/sections/'
sections_dist = len(sections_suff.split(os.sep))
entries = []
entries.append(
"""
Autogenerated by the /rst/gendoc.py script
==============
OIOIOI Modules
==============
List of modules
---------------
"""
)
oioioi_dirname = os.path.dirname(oioioi.__file__)
sections_dirname = os.path.join(oioioi_dirname, sections_suff)
for root, dirs, files in os.walk(oioioi_dirname):
dirs.sort()
rel_root = os.path.relpath(root, sections_dirname)
module_name = '.'.join(rel_root.split(os.sep)[sections_dist - 1 :])
if 'README.rst' in files:
entries.append(
'**%s**\n\n.. include:: %s/README.rst\n\n' % (module_name, rel_root)
)
elif len(rel_root.split(os.sep)) == sections_dist and 'locale' not in module_name:
print("No README.rst in %s" % module_name)
content = ''.join(entries)
if len(sys.argv) > 1 and (sys.argv[1] == '--verbose' or sys.argv[1] == '-v'):
print(content)
f = open(os.path.join(oioioi_dirname, sections_suff, 'modules.rst'), 'w')
f.write(content)
f.close()