Fix external Web-Modules
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshResource.py
1 from twisted.web import http, resource
2 from EPGRefresh import epgrefresh
3
4 # pretty basic resource which is just present to have a way to start a
5 # forced refresh through the webif
6 class EPGRefreshResource(resource.Resource):
7         def __init__(self):
8                 resource.Resource.__init__(self)
9
10         def render(self, req):
11                 res = False
12                 if req.args.has_key("refresh"):
13                         if epgrefresh.forceRefresh():
14                                 output = "initiated refresh"
15                                 res = True
16                         else:
17                                 output = "could not initiate refresh"
18                 else:
19                         output = "unknown command"
20
21                 result = """<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n
22                         <e2simplexmlresult>\n
23                                 <e2state>%s</e2state>\n
24                                 <e2statetext>%s</e2statetext>\n
25                         </e2simplexmlresult>
26                         """ % ('true' if res else 'false', output)
27
28                 req.setResponseCode(http.OK)
29                 req.setHeader('Content-type', 'application; xhtml+xml')
30                 req.setHeader('charset', 'UTF-8')
31                 
32                 return result