-
Notifications
You must be signed in to change notification settings - Fork 2
/
webserver.py
executable file
·225 lines (173 loc) · 7.21 KB
/
webserver.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
"""
webserver.py
Copyright (c) 2015-2016 Dany Vohl, David G. Barnes, Christopher J. Fluke,
Yuri Benovitski, Tsz Ho Wong, Owen L Kaluza, Toan D. Nguyen.
This file is part of encube.
encube is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
encube is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with encube. If not, see <http://www.gnu.org/licenses/>.
We would appreciate it if research outcomes using encube would
provide the following acknowledgement:
"Visual analytics of multidimensional data was conducted with encube."
and a reference to
Dany Vohl, David G. Barnes, Christopher J. Fluke, Govinda Poudel, Nellie Georgiou-Karistianis,
Amr H. Hassan, Yuri Benovitski, Tsz Ho Wong, Owen L Kaluza, Toan D. Nguyen, C. Paul Bonnington. (2016).
Large-scale comparative visualisation of sets of multidimensional data. PeerJ Computer Science, In Press.
"""
#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
import urlparse
import socket
import os
import sys
from encube_m import EncubeMResource
import request_handle
'''
Authors: Owen Kaluza, Dany Vohl, 2015-2016.
'''
if len(sys.argv) == 2:
config_file = sys.argv[1]
def connect(encube_m_obj):
try:
encube_m_obj.connect_to_encube_pr()
except:
print "Web server cannot connect to encube_pr"
PORT = 8000
# Initialise encube_m object
with EncubeMResource(config_file) as encube_m_obj:
encube_m_obj.to_json_file(encube_m_obj.config["control_dir"] + '/' + encube_m_obj.config["output_json"])
connect(encube_m_obj)
os.chdir("control")
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
# Extract and print the contents of the POST
length = int(self.headers['Content-Length'])
post_data = urlparse.parse_qs(self.rfile.read(length).decode('utf-8'))
#print post_data
#for key, value in post_data.iteritems():
# print "KEY %s= VALUE %s" % (key, value[0])
def socket_send(data):
#create an INET, STREAMing socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#now forward the data to the perl script
s.connect(("localhost", 7777))
s.send(data)
s.close()
"""
if (encube_m_obj.status == 0):
print "Trying to connect to encube_pr"
connect(encube_m_obj)
if (encube_m_obj.status):
print "Connected to encube_pr"
else:
print "I won't send anything this time. Ghost call."
send_json_back = False
else:
"""
send_json_back, json_data = act_on_post(post_data)
if send_json_back:
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json_data)
else:
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
def act_on_post(post_data):
if "data" in post_data:
request_handle.data(encube_m_obj, post_data)
return False, False
if "moment" in post_data:
request_handle.moment(encube_m_obj, post_data)
return False, False
if "range_filter" in post_data:
request_handle.range_filter(encube_m_obj, post_data)
return False, False
if "sort" in post_data:
request_handle.sort(encube_m_obj, post_data)
return False, False
if "region" in post_data:
request_handle.region(encube_m_obj, post_data)
return False, False
if "minicaveReorder" in post_data:
request_handle.minicaveReorder(encube_m_obj, post_data)
return False, False
if "reorder" in post_data:
request_handle.reorder(encube_m_obj, post_data)
return False, False
if "loadOne" in post_data:
request_handle.load_one(encube_m_obj, post_data)
return False, False
if "update_selected" in post_data:
request_handle.update_selected(encube_m_obj, post_data)
return False, False
if "histogram" in post_data:
json_data = request_handle.histogram(encube_m_obj, post_data)
if json_data != False:
return True, json_data
else:
return False, False
if "moment" in post_data:
json_data = request_handle.moment(encube_m_obj, post_data)
if json_data != False:
return True, json_data
else:
return False, False
if "ntracks" in post_data:
json_data = request_handle.ntracks(encube_m_obj, post_data)
if json_data != False:
return True, json_data
else:
return False, False
if "state" in post_data:
json_data = request_handle.state(encube_m_obj, post_data)
if json_data != False:
return True, json_data
else:
return False, False
if "save_history" in post_data:
request_handle.save_history(encube_m_obj)
return False, False
if "load_state" in post_data:
json_data = request_handle.load_history_record(encube_m_obj, post_data)
if json_data != False:
return True, json_data
else:
return False, False
if "autospin" in post_data:
request_handle.autospin(encube_m_obj, post_data)
return False, False
if "zoomIn" in post_data:
request_handle.zoom_in(encube_m_obj, post_data)
return False, False
if "zoomOut" in post_data:
request_handle.zoom_out(encube_m_obj, post_data)
return False, False
if "showStats" in post_data:
request_handle.show_stats(encube_m_obj, post_data)
return False, False
if "stopEncubePR" in post_data:
encube_m_obj.send_to_all_slaves("KQ")
return False, False
if "startEncubePR" in post_data:
# Would need to be started on a different thread I think. Not currently working from the browser.
encube_m_obj.start_encube_pr()
return False, False
# Nothing was found/done.
print "Nothing prepared for what was asked from client. Nothing done."
return False, False
Handler = ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()