return e2simplexmlresult rather than plain text and save autotimer.xml before removin...
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshResource.py
1 from twisted.web2 import http, http_headers, resource, responsecode
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                 XML_HEADER = {'Content-type': http_headers.MimeType('application', 'xhtml+xml', (('charset', 'UTF-8'),))}
29                 return http.Response(responsecode.OK, XML_HEADER, stream = result)
30