/
webserver.py
42 lines (30 loc) · 1.09 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
from twisted.web import server, resource, static
from twisted.internet import reactor
import threading, rb, os
import source
import player
class Root(resource.Resource):
isLeaf = False
def __init__(self, datadir):
resource.Resource.__init__(self)
self.datadir = datadir
def render_GET(self, request):
pass
def getChild(self, path, request):
return static.File(os.path.join(self.datadir, 'static', 'index.html'))
class WebServer(threading.Thread):
def __init__(self, shell, datadir, port=8888):
threading.Thread.__init__(self)
self.shell = shell
self.port = port
self.site = Root(datadir)
self.site.putChild("static", static.File(os.path.join(datadir, 'static')))
sources = source.Sources(self.shell)
self.site.putChild("playlist", sources)
self.site.putChild("player", player.Player(self.shell, sources))
def run(self):
reactor.listenTCP(self.port, server.Site(self.site))
reactor.run(installSignalHandlers=False)
def stop(self):
reactor.stop()
# vi:ex:ts=4:et