-
Notifications
You must be signed in to change notification settings - Fork 0
/
ride_http_server.py
52 lines (42 loc) · 1.25 KB
/
ride_http_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
import logging
from http.server import SimpleHTTPRequestHandler, HTTPServer
from roller_coaster import Coaster
from ride_single import SingleRideStateMachine
from ride_clock import ClockRideStateMachine
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
)
coaster = Coaster()
coaster.start()
clockRide = ClockRideStateMachine(coaster)
singleRide = SingleRideStateMachine(coaster)
hostName = "0.0.0.0"
serverPort = 8080
class DrahaController(SimpleHTTPRequestHandler):
def do_GET(self):
self.path = 'index.html'
return SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
global current, single, clock
if self.path.endswith('/single'):
clockRide.stop()
singleRide.start()
elif self.path.endswith('/clock'):
singleRide.stop()
clockRide.start()
elif self.path.endswith('/stop'):
singleRide.stop()
clockRide.stop()
return self.do_GET()
webServer = HTTPServer((hostName, serverPort), DrahaController)
logging.info("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
coaster.stop()
clockRide.stop()
singleRide.stop()
logging.info("Server stopped.")