-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateHtml.py
49 lines (40 loc) · 1.5 KB
/
generateHtml.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
#!/usr/bin/env python
import os
import argparse
import datetime
import subprocess
import contextlib
import jinja2
import packaging.utils
parser = argparse.ArgumentParser()
parser.add_argument(
'wheel',
type=lambda path: os.path.basename(path),
help='Path to wheel. Will be used to determine the version. It can also be just the wheel filename.'
)
parser.add_argument(
'outputDir',
help='Directory where HTML files will be rendered to.'
)
args = parser.parse_args()
_, version, _, _ = packaging.utils.parse_wheel_filename(args.wheel)
commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], universal_newlines=True, cwd='OpenTimelineIO')
commitISOTime = subprocess.check_output(['git', 'show', '-s', '--format=%cI', 'HEAD'], universal_newlines=True, cwd='OpenTimelineIO')
env = jinja2.Environment(
loader=jinja2.FileSystemLoader("public"),
autoescape=jinja2.select_autoescape()
)
with contextlib.suppress(FileExistsError):
os.makedirs(args.outputDir)
for templateName in ['index', 'console']:
template = env.get_template(f'{templateName}.html.in')
with open(f'{args.outputDir}/{templateName}.html', 'w') as fd:
fd.write(
template.render(
version=str(version),
commit=commit.strip(),
wheel=args.wheel,
originalTimestamp=commitISOTime.strip(),
utcTimestamp=datetime.datetime.fromisoformat(commitISOTime.strip()).astimezone(datetime.timezone.utc)
)
)