1 from Plugins.Plugin import PluginDescriptor
6 from twisted.internet import reactor
7 from twisted.web2 import server, channel, static, resource, stream, http_headers, responsecode, http
8 from twisted.python import util
11 class ScreenPage(resource.Resource):
12 def __init__(self, path):
15 def render(self, req):
18 return http.Response(200, stream="please wait until enigma has booted")
20 class myProducerStream(stream.ProducerStream):
21 closed_callback = None
24 if self.closed_callback:
25 self.closed_callback()
26 stream.ProducerStream.close(self)
28 s = myProducerStream()
29 webif.renderPage(s, self.path, req, sessions[0]) # login?
31 return http.Response(stream=s)
33 def locateChild(self, request, segments):
34 path = '/'.join(["web"] + segments)
39 return ScreenPage(path), ()
41 class Toplevel(resource.Resource):
44 def render(self, req):
45 return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},
46 stream='Hello! You want go to <a href="/web/">OSD</a> instead.')
48 child_web = ScreenPage("/") # "/web"
49 child_hdd = static.File("/hdd")
50 child_webdata = static.File(util.sibpath(__file__, "web-data")) # FIXME: web-data appears as webdata
52 site = server.Site(Toplevel())
54 reactor.listenTCP(80, channel.HTTPFactory(site))
56 def autostart(reason, **kwargs):
57 if "session" in kwargs:
59 sessions.append(kwargs["session"])
66 print "twisted not available, not starting web services"
68 def Plugins(**kwargs):
69 return PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart)