1 from Plugins.Plugin import PluginDescriptor
5 # set DEBUG to True, if twisted should write logoutput to a file.
7 DEBUGFILE= "/tmp/twisted.log"
10 from twisted.internet import reactor
11 from twisted.web2 import server, channel, static, resource, stream, http_headers, responsecode, http
12 from twisted.python import util
15 class ScreenPage(resource.Resource):
16 def __init__(self, path):
19 def render(self, req):
22 return http.Response(200, stream="please wait until enigma has booted")
24 class myProducerStream(stream.ProducerStream):
25 closed_callback = None
28 if self.closed_callback:
29 self.closed_callback()
30 stream.ProducerStream.close(self)
32 s = myProducerStream()
33 webif.renderPage(s, self.path, req, sessions[0]) # login?
35 return http.Response(stream=s)
37 def locateChild(self, request, segments):
38 path = '/'.join(["web"] + segments)
43 return ScreenPage(path), ()
45 class Toplevel(resource.Resource):
48 def render(self, req):
49 return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},
50 stream='Hello! You want go to <a href="/web/">OSD</a> instead.')
52 child_web = ScreenPage("/") # "/web"
53 child_hdd = static.File("/hdd")
54 child_webdata = static.File(util.sibpath(__file__, "web-data")) # FIXME: web-data appears as webdata
56 site = server.Site(Toplevel())
58 reactor.listenTCP(80, channel.HTTPFactory(site))
60 def autostart(reason, **kwargs):
61 if "session" in kwargs:
63 sessions.append(kwargs["session"])
69 in normal console output, twisted will print only the first Traceback.
70 is this a bug in twisted or a conflict with enigma2?
71 with this option enabled, twisted will print all TB to the logfile
72 use tail -f <file> to view this log
75 from twisted.python.log import startLogging
76 print "start twisted logfile, writing to %s" % DEBUGFILE
77 startLogging(open(DEBUGFILE,'w'))
81 print "twisted not available, not starting web services"
83 def Plugins(**kwargs):
84 return PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart)