remove old import (which caused an exception)
[enigma2-plugins.git] / webinterface / src / WebChilds / Toplevel.py
1 from twisted.web2 import resource, static, responsecode, http, http_headers
2 from twisted.python import util
3
4 from Components.config import config
5
6 from Plugins.Extensions import WebInterface
7 from Screenpage import ScreenPage
8 from FileStreamer import FileStreamer
9 from Screengrab import GrabResource
10 from IPKG import IPKGResource
11 from PlayService import ServiceplayerResource
12 from Uploader import UploadResource
13 from ServiceListSave import ServiceList
14
15 class Toplevel(resource.Resource):
16     addSlash = True
17     def __init__(self,session):
18         self.session = session
19         resource.Resource.__init__(self)
20         
21         self.putChild("web",ScreenPage(self.session,util.sibpath(WebInterface.__file__, "web"))) # "/web/*"
22         self.putChild("webdata",static.File(util.sibpath(WebInterface.__file__, "web-data"))) # FIXME: web-data appears as webdata
23         self.putChild("file",FileStreamer())
24         self.putChild("grab",GrabResource())
25         self.putChild("ipkg",IPKGResource())
26         self.putChild("play",ServiceplayerResource(self.session))
27         self.putChild("wap",RedirectorResource("/web/wap/"))# shorten and simplify url to wap-pages
28         self.putChild("upload",UploadResource())
29         self.putChild("servicelist",ServiceList(self.session))
30
31         if config.plugins.Webinterface.includehdd.value is True:
32             self.putChild("hdd",static.File("/hdd"))
33         
34     def render(self, req):
35         fp = open(util.sibpath(WebInterface.__file__, "web-data")+"/index.html")
36         s = fp.read()
37         fp.close()
38         return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},stream=s)
39
40     def locateChild(self, request, segments):
41         print "[WebIf]",request.remoteAddr.host,request.method,request.path,request.args
42         return resource.Resource.locateChild(self, request, segments)
43
44 class RedirectorResource(resource.Resource):
45     """ 
46         this class can be used to redirect a request to a specified uri
47     """
48     def __init__(self,uri):
49         self.uri = uri
50         resource.Resource.__init__(self)
51     def render(self, req):
52         return http.RedirectResponse(self.uri)
53
54