-
Notifications
You must be signed in to change notification settings - Fork 0
/
runserver.py
34 lines (28 loc) · 1.29 KB
/
runserver.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
import subprocess, os
import sys
import webbrowser
import time
os.system("")
class bcolors:
OKBLUE = '\033[94m'
WARNING = '\033[93m'
LINE = '\033[90m'
ENDC = '\033[0m'
print(f"{bcolors.LINE}---------------------------------------{bcolors.ENDC}")
print(f"{bcolors.OKBLUE}Opening page...")
print(f"{bcolors.LINE}---------------------------------------{bcolors.ENDC}")
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
installed_packages = [r.decode().split('==')[0] for r in reqs.split()]
# use rangehttpserver as it supports range headers (fixes video scrubbing in the browser)
if 'rangehttpserver' not in installed_packages:
os.system("title " + "Installing packages...")
print(f"{bcolors.LINE}---------------------------------------{bcolors.WARNING}")
print(f"{bcolors.OKBLUE}Installing packages...")
print(f"{bcolors.LINE}---------------------------------------")
subprocess.run('pip install -r requirements.txt', shell=True)
print(f"{bcolors.LINE}---------------------------------------")
# make a localhost web server and open generated index.html, since CORS blocks file:// fetching
os.system("title " + "Running web server...")
subprocess.Popen(['python', '-m', 'RangeHTTPServer'])
time.sleep(3)
webbrowser.open('http://localhost:8000/index.html')