-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev_server.py
executable file
·52 lines (39 loc) · 1.17 KB
/
dev_server.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
#!/usr/bin/env python3
import os
import subprocess
import time
import http.server
import socketserver
def file_times(path):
for root, _, files in os.walk(path):
for file in files:
yield os.stat(os.path.join(root, file)).st_mtime
def build():
try:
os.system("rm -rf web")
os.system("make web")
os.system("mkdir web")
os.system("cp src/index.html web")
os.system("cp target/wasm32-unknown-emscripten/release/deps/sdl_emscripten_template.wasm web/")
os.system("cp target/wasm32-unknown-emscripten/release/deps/sdl_emscripten_template.js web/")
except:
quit()
def run():
return subprocess.Popen("python3 -m http.server --bind 0.0.0.0 --directory web", shell=True)
def get_output(func, proc):
if proc.stdout is not None:
for line in proc.stdout.splitlines():
print(f"[{func}] {line}")
if __name__ == '__main__':
build()
process = run()
last_modified = max(file_times("./src"))
while True:
current_modified = max(file_times("./src"))
if current_modified > last_modified:
last_modified = current_modified
print("\nRestarting process.")
process.kill()
build()
process = run()
time.sleep(1)