-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeindex.py
More file actions
executable file
·49 lines (38 loc) · 884 Bytes
/
makeindex.py
File metadata and controls
executable file
·49 lines (38 loc) · 884 Bytes
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
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
from jinja2 import Template
tpl = '''
<!doctype html>
<head>
<title>DUNE-gdt Tutorials</title>
</head>
<body>
<h1>Available versions</h1>
<ul>
{%- for subdir in subdirs -%}
<li>
<a href="{{ subdir }}/index.html">{{ subdir }}</a>
</li>
{%- endfor %}
</ul>
</body>
</html>
'''
def _make_list(root, name='main'):
subdirs = []
for it in root.iterdir():
if it.is_dir() and (it / 'index.html').is_file():
subdirs.append(it.name)
return sorted(subdirs)
def make_index(path):
path = path.resolve()
with (path / 'list.html').open('wt') as out:
out.write(Template(tpl).render(subdirs=_make_list(path)))
if __name__ == '__main__':
try:
path = Path(sys.argv[1])
except IndexError:
path = Path().cwd()
make_index(path)