-
Notifications
You must be signed in to change notification settings - Fork 2
/
vis.py
60 lines (42 loc) · 1.57 KB
/
vis.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
import os
import sys
import platform
from subprocess import call
def view_replay(browser: str, log: str):
on_windows = "Windows" in platform.system()
output_filename = log.replace(".hlt", ".htm")
path_to_file = os.path.join("visualizer", output_filename)
if on_windows:
path_to_file = os.path.join(os.getcwd(), path_to_file)
if not browser.endswith(".exe"):
browser += ".exe"
if not os.path.exists(output_filename):
# parse replay file
with open(log, 'r') as f:
replay_data = f.read()
# parse template html
with open(os.path.join("visualizer", "Visualizer.htm")) as f:
html = f.read()
html = html.replace("FILENAME", log)
html = html.replace("REPLAY_DATA", replay_data)
# dump replay html file
with open(os.path.join("visualizer", output_filename), 'w') as f:
f.write(html)
if on_windows:
# add quotes to browser executable name/path if it contains whitespace or parantheses
for c in " \t()":
if c in browser:
browser = '"' + browser + '"'
break
path_to_file = "file://" + path_to_file
start_vis_cmd = f"{browser} {path_to_file}"
if on_windows:
start_vis_cmd = "start /B " + start_vis_cmd
else:
start_vis_cmd += " &"
with open(os.devnull, "w") as null:
call(start_vis_cmd, shell=True, stderr=sys.stderr, stdout=null)
def main():
view_replay(sys.argv[1], sys.argv[2])
if __name__ == "__main__":
main()