forked from expfactory/expfactory-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_battery.py
37 lines (32 loc) · 1017 Bytes
/
run_battery.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
#!/usr/bin/env python
import argparse
import http.server
import os
import socketserver
import sys
import webbrowser
parser = argparse.ArgumentParser()
parser.add_argument('--folder', help='Folder with battery and experiments (document root)',default=None)
parser.add_argument('--port', help='Web server port', default=8080)
try:
args = parser.parse_args()
except:
parser.print_help()
sys.exit(0)
# If folder not specified, assume user means PWD
folder = args.folder
if folder == None:
print("No web root folder specified, serving present working directory...")
folder = os.getcwd()
print("Serving experiment from from %s" %(folder))
try:
os.chdir(folder)
port = int(args.port)
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", port), Handler)
print("Preview experiment at localhost:%s" %port)
webbrowser.open("http://localhost:%s" %(port))
httpd.serve_forever()
except:
print("Stopping web server...")
httpd.server_close()