-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpage.py
55 lines (46 loc) · 1.74 KB
/
webpage.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
import os
import shutil
from jinja2 import Environment, PackageLoader, select_autoescape
env = Environment(
loader=PackageLoader("webpage"),
# searches in "templates/" directory next to the webpage module (this file)
# autoescape=select_autoescape()
)
template = env.get_template("index.html.template")
def index(experiment_dir, visualization_dirs):
"""
Create an index page with thumbnails that link to the individual runs.
Ideally the paths in the web page are relative to the index file itself
so that the webpage can be re-located.
"""
outfile = open(os.path.join(experiment_dir, 'index.html'), 'wt')
title = os.path.basename(os.path.normpath(experiment_dir))
print(
f"""
<html>
<head>
<title>{title}</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
</head>
<body>
<h1>{title}</h1>
""", file=outfile)
sdir = os.path.dirname(os.path.abspath(__file__))
shutil.copyfile(os.path.join(sdir,'favicon.png'),
os.path.join(experiment_dir,'favicon.png'))
for d,params in visualization_dirs:
d = os.path.relpath(d, start=experiment_dir) # convert to a relative path
print(f'<a href={d}/index.html> <img src={d}/thumbnail.png> </a>', file=outfile)
print(
"""
</body>
</html>
""", file=outfile)
for d,run in visualization_dirs:
# copy webpage template (possibly use template engine later)
#sdir = os.path.dirname(os.path.abspath(__file__))
#shutil.copyfile(os.path.join(sdir,'run_index.html'),
# os.path.join(d,'index.html'))
dest = os.path.join(d,'index.html')
outfile = open(dest, 'wt')
print(template.render({'run':run}), file=outfile)