-
Notifications
You must be signed in to change notification settings - Fork 0
/
proga.py
executable file
·155 lines (110 loc) · 3.73 KB
/
proga.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
import os, os.path
import random
import string
import time
import datetime
import cherrypy
from cherrypy.process import wspbus, plugins
from cherrypy.process.plugins import Monitor
from cherrypy import log
import progaconstants
from automator import Automator
from traffic import Traffic
from prediction import PredictionEngine
from listener import FSListener
from hotspots import HotSpotter
from planner import Planner
from cherrypy import log
import sys
class ProGA(object):
def __init__(self):
cherrypy.log("Starting ProGA server", context='AUTO')
@cherrypy.expose
def index(self):
return 'Hello, this is the proga prototype'
def str2bool(str):
return v.lower() in ("yes", "true", "t", "1")
if __name__ == '__main__':
args = sys.argv
proga_conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd()),
#'tools.staticdir.dir': './',
#'tools.staticdir.on': True,
#'log.access_file' : "access.log",
#'log.error_file' : "error.log",
#'log.screen' : False
},
}
listener_conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers' : [('Content-Type','text/plain')]
}
}
prediction_conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers' : [('Content-Type','text/plain')]
}
}
hotspots_conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers' : [('Content-Type','text/plain')]
}
}
planner_conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers' : [('Content-Type','text/plain')]
}
}
traffic_conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers' : [('Content-Type','text/plain')]
}
}
auto_conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers' : [('Content-Type','text/plain')]
}
}
cherrypy.config.update({'server.socket_host': '0.0.0.0',
'server.socket_port': progaconstants.LISTEN_PORT,
'log.screen': False,
'log.access_file': './access.log',
'log.error_file': './proga.log'})
traffic = Traffic(cherrypy.engine,progaconstants.PLAYER_SLEEP_SECONDS)
predictionEngine = PredictionEngine(cherrypy.engine,progaconstants.PREDICTION_SLEEP_SECONDS, traffic)
hotspots = HotSpotter(cherrypy.engine,progaconstants.HOTSPOTS_SLEEP_SECONDS)
planner = Planner(cherrypy.engine,progaconstants.PLANNER_SLEEP_SECONDS)
cherrypy.tree.mount(ProGA(), '/', proga_conf)
cherrypy.tree.mount(FSListener(), '/listener', listener_conf)
cherrypy.tree.mount(traffic, '/traffic', traffic_conf)
cherrypy.tree.mount(predictionEngine, '/prediction', traffic_conf)
cherrypy.tree.mount(hotspots, '/hotspots', hotspots_conf)
cherrypy.tree.mount(planner, '/planner', planner_conf)
automator = None
if len(args)==2:
#auto = args[1]
scenario = args[1]
automator = Automator(cherrypy.engine, scenario,None,progaconstants.PLAYER_SLEEP_SECONDS)
elif len(args)==3:
scenario = args[1]
selfTrack = args[2]
automator = Automator(cherrypy.engine, scenario, selfTrack,progaconstants.PLAYER_SLEEP_SECONDS)
cherrypy.tree.mount(automator,'/automator',auto_conf)
cherrypy.engine.start()
cherrypy.engine.publish(progaconstants.PROGA_IS_READY_CHANNEL_NAME)
cherrypy.engine.block()