[WebIf] - remove accidently added/copied files
[enigma2-plugins.git] / webinterface / src / WebChilds / Toplevel.py
1 from twisted.web import resource, static
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 from Tools.Directories import resolveFilename, SCOPE_MEDIA
16
17 from External.__init__ import importExternalModules
18 externalChildren = []
19
20 """
21         .htc Files for IE Fixes need a certain Content-Type
22 """
23 import mimetypes
24 mimetypes.add_type('text/x-component', '.htc')
25 mimetypes.add_type('text/cache-manifest', '.appcache')
26 static.File.contentTypes = static.loadMimeTypes()
27
28 if hasattr(static.File, 'render_GET'):
29         class File(static.File):
30                 def render_POST(self, request):
31                         return self.render_GET(request)
32 else:
33         File = static.File
34
35 def addExternalChild(child):
36         externalChildren.append(child)
37
38 def getToplevel(session):
39         root = File(util.sibpath(__file__, "web-data/tpl/default"))
40
41         root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True) ) # "/web/*"
42         root.putChild("web-data", File(util.sibpath(__file__, "web-data")))
43         root.putChild("file", FileStreamer())
44         root.putChild("grab", GrabResource())
45         res = IPKGResource()
46         root.putChild("opkg", res)
47         root.putChild("ipkg", res)
48         root.putChild("play", ServiceplayerResource(session))
49         root.putChild("wap", RedirectorResource("/mobile/"))
50         root.putChild("mobile", ScreenPage(session, util.sibpath(__file__, "mobile"), True) )
51         root.putChild("m",ScreenPage(session, util.sibpath(__file__, "m"), True))
52         root.putChild("upload", UploadResource())
53         root.putChild("servicelist", ServiceList(session))
54         root.putChild("streamcurrent", RedirecToCurrentStreamResource(session))
55
56         if config.plugins.Webinterface.includemedia.value is True:
57                 root.putChild("media", File(resolveFilename(SCOPE_MEDIA)))
58                 root.putChild("hdd", File(resolveFilename(SCOPE_MEDIA, "hdd")))
59
60
61         importExternalModules()
62
63         for child in externalChildren:
64                 if len(child) > 1:
65                         root.putChild(child[0], child[1])
66
67         return root
68
69 class RedirectorResource(resource.Resource):
70         """
71                 this class can be used to redirect a request to a specified uri
72         """
73         def __init__(self, uri):
74                 self.uri = uri
75                 resource.Resource.__init__(self)
76
77         def render(self, request):
78                 request.redirect(self.uri)
79                 request.finish()
80