Cleanup Imports
[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.WebInterface import __file__ 
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 from RedirecToCurrentStream import RedirecToCurrentStreamResource
15
16 from External.__init__ import importExternalModules
17 externalChildren = []
18
19 def addExternalChild(child):
20         externalChildren.append(child)
21
22 class Toplevel(resource.Resource):
23         addSlash = True
24         def __init__(self,session):
25                 self.session = session
26                 resource.Resource.__init__(self)
27
28                 self.putChild("web", ScreenPage(self.session,util.sibpath(__file__, "web"))) # "/web/*"
29                 self.putChild("web-data", static.File(util.sibpath(__file__, "web-data")))
30                 self.putChild("file", FileStreamer())
31                 self.putChild("grab", GrabResource())
32                 self.putChild("ipkg", IPKGResource())
33                 self.putChild("play", ServiceplayerResource(self.session))
34                 self.putChild("wap", RedirectorResource("/web/wap/"))# shorten and simplify url to wap-pages
35                 self.putChild("upload", UploadResource())
36                 self.putChild("servicelist", ServiceList(self.session))
37                 self.putChild("streamcurrent", RedirecToCurrentStreamResource(session))
38                         
39                 if config.plugins.Webinterface.includemedia.value is True:
40                         self.putChild("media", static.File("/media"))
41                         self.putChild("hdd", static.File("/media/hdd"))
42                         
43                 
44                 importExternalModules()
45
46                 for child in externalChildren:
47                         if len(child) == 2:
48                                 self.putChild(child[0], child[1])
49
50
51         def render(self, req):
52                 fp = open(util.sibpath(__file__, "web-data/tpl/default")+"/index.html")
53                 s = fp.read()
54                 fp.close()
55                 return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},stream=s)
56
57         def locateChild(self, request, segments):
58                 print "[WebIf]", request.remoteAddr.host,request.method,request.path,request.args
59                 return resource.Resource.locateChild(self, request, segments)
60
61 class RedirectorResource(resource.Resource):
62         """
63                 this class can be used to redirect a request to a specified uri
64         """
65         def __init__(self,uri):
66                 self.uri = uri
67                 resource.Resource.__init__(self)
68         def render(self, req):
69                 return http.RedirectResponse(self.uri)
70