forked from acm-uiuc/chroma-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·60 lines (50 loc) · 1.49 KB
/
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
52
53
54
55
56
57
58
59
60
#!./virt_env/bin/python
import os
import cherrypy as http
import subprocess
import signal
import simplejson as json
p = None
class Serv:
def __turn_off(self):
global p
if p:
os.kill(p.pid, signal.SIGTERM)
@http.expose
def play(self, animation):
global p
self.__turn_off()
animations = os.listdir('./animations/')
if animation in animations:
p = subprocess.Popen(['env','PYTHONPATH=./osc:$PYTHONPATH','python','animations/%s/main.py'%animation])
return "Animation %s started"%animation
return "Unknown animation %s"%animation
@http.expose
def off(self):
self.__turn_off()
return "Turned off"
@http.expose
def pull(self):
p = os.popen('git pull origin master','r')
output = ""
while 1:
line = p.readline()
if not line: break
output += line + '\n'
animations = os.listdir('./animations/')
aData = {}
for a in animations:
json_data=open('animations/%s/manifest.json'%a)
data = json.load(json_data)
aData[a] = data
json_data.close()
ret_data = {'output':output, "animations":aData}
return json.dumps(ret_data)
if __name__ == "__main__":
config = {
}
http.tree.mount(Serv(), '/', config = config)
http.config.update( {'server.socket_host':"0.0.0.0", 'server.socket_port':8181 } )
http.engine.signal_handler.subscribe()
http.engine.start()
http.engine.block()