/
haut-webserver.py
executable file
·70 lines (57 loc) · 1.66 KB
/
haut-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
#!/usr/bin/python3
import os
import cherrypy
from mako.template import Template
from network import Network
from config import *
class Webserver(object):
def __init__(self):
cherrypy.engine.subscribe('stop', self.stop)
self.net = Network(WEBSERVER_IP, WEBSERVER_PORT)
# spusti se pri zapinani
def stop(self):
# spusti se pri vypinani
pass
@cherrypy.expose
def index(self):
# exposed metoda -- zavolali jsme /
return base.render()
def doit(self, action, value):
# spustit ledky
data = dict()
data["key"] = action
data["value"] = value
self.net.send(data, SERVER_IP, SERVER_PORT)
@cherrypy.expose
def set(self, value):
self.doit("set", value)
return self.index()
@cherrypy.expose
def get(self, value):
self.doit("get", value)
tmp = self.net.recv()
# should be recv
return tmp
if __name__ == '__main__':
conf = {
'/': {
#'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd()),
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './static'
},
'/css': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './static/css'
},
'/js': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './static/js'
}
}
cherrypy.server.socket_host = "0.0.0.0"
cherrypy.server.socket_port = 80
base = Template(filename='./static/base.html')
cherrypy.quickstart(Webserver(), '/', conf)