link correct url for web interface sample
[enigma2.git] / lib / python / Plugins / Extensions / WebInterface / plugin.py
index c61424c..71c4afc 100644 (file)
@@ -4,27 +4,41 @@ sessions = [ ]
 
 def startWebserver():
        from twisted.internet import reactor
 
 def startWebserver():
        from twisted.internet import reactor
-       from twisted.web2 import server, http, static, resource, stream
+       from twisted.web2 import server, http, static, resource, stream, http_headers, responsecode
+       from twisted.python import util
        import webif
 
        class ScreenPage(resource.Resource):
        import webif
 
        class ScreenPage(resource.Resource):
+               def __init__(self, path):
+                       self.path = path
+                       
                def render(self, req):
                        global sessions
                        if sessions == [ ]:
                def render(self, req):
                        global sessions
                        if sessions == [ ]:
-                               return http.Response("please wait until enigma has booted")
+                               return http.Response(200, stream="please wait until enigma has booted")
                        
                        s = stream.ProducerStream()
                        
                        s = stream.ProducerStream()
-                       webif.renderPage(s, req, sessions[0])  # login?
+                       webif.renderPage(s, self.path, sessions[0])  # login?
                        return http.Response(stream=s)
 
                        return http.Response(stream=s)
 
+               def locateChild(self, request, segments):
+                       path = '/'.join(["web"] + segments)
+                       if path[-1:] == "/":
+                               path += "index"
+                       
+                       path += ".xml"
+                       return ScreenPage(path), ()
+
        class Toplevel(resource.Resource):
                addSlash = True
                
                def render(self, req):
        class Toplevel(resource.Resource):
                addSlash = True
                
                def render(self, req):
-                       return 'Hello! you want probably go to <a href="/test">the test</a> instead.'
+                       return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},
+                               stream='Hello! you want probably go to <a href="/web">the test</a> instead.')
 
 
-               child_test = ScreenPage() # "/test"
+               child_web = ScreenPage("/") # "/web"
                child_hdd = static.File("/hdd")
                child_hdd = static.File("/hdd")
+               child_webdata = static.File(util.sibpath(__file__, "web-data"))
 
        site = server.Site(Toplevel())
        
 
        site = server.Site(Toplevel())
        
@@ -37,10 +51,10 @@ def autostart(reason, **kwargs):
                return
 
        if reason == 0:
                return
 
        if reason == 0:
-               try:
+               #try:
                        startWebserver()
                        startWebserver()
-               except ImportError:
-                       print "twisted not available, not starting web services"
+               #except ImportError:
+               #       print "twisted not available, not starting web services"
 
 def Plugins(**kwargs):
        return PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart)
 
 def Plugins(**kwargs):
        return PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart)