-
Notifications
You must be signed in to change notification settings - Fork 22
/
statshtml.py
62 lines (44 loc) · 1.07 KB
/
statshtml.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
import sys
from tf.core.files import dirExists, dirContents, extNm, stripExt
statsDir = sys.argv[1]
indexFile = f"{statsDir}/index.html"
if not dirExists(statsDir):
print(f"No stats directory found: {statsDir}")
sys.exit(1)
files = dirContents(statsDir)[0]
mods = dirContents(f"{statsDir}/mod")[0]
htmlPre = """\
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<h2>Overview</h2>
<ul>
"""
htmlHead = """\
</ul>
<h2>By module</h2>
<ul>
"""
htmlPost = """\
</ul>
</body>
</html>
"""
htmlInner = []
for file in sorted(files):
if extNm(file) != "txt":
continue
ind = " " * 12
name = stripExt(file)
htmlInner.append(f"""{ind}<li><a href="{file}">{name}</a></li>""")
htmlInner.append(htmlHead)
for mod in sorted(mods):
ind = " " * 12
name = stripExt(mod)
htmlInner.append(f"""{ind}<li><a href="mod/{mod}">{name}</a></li>""")
with open(indexFile, "w") as fh:
htmlInner = "\n".join(htmlInner)
fh.write(f"{htmlPre}{htmlInner}{htmlPost}")