return e2simplexmlresult rather than plain text and save autotimer.xml before removin...
authorMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Thu, 27 Aug 2009 07:01:29 +0000 (07:01 +0000)
committerMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Thu, 27 Aug 2009 07:01:29 +0000 (07:01 +0000)
autotimer/src/AutoTimerResource.py
epgrefresh/src/EPGRefreshResource.py

index 4f6ab4b..ad918a1 100644 (file)
@@ -1,4 +1,4 @@
-from twisted.web2 import resource, responsecode, http
+from twisted.web2 import http, http_headers, resource, responsecode
 from AutoTimer import AutoTimer
 from . import _
 
@@ -10,7 +10,9 @@ class AutoTimerResource(resource.Resource):
 
        def render(self, req):
                from plugin import autotimer
+
                remove = False
+               res = False
                if autotimer is None:
                        autotimer = AutoTimer()
                        remove = True
@@ -18,10 +20,21 @@ class AutoTimerResource(resource.Resource):
                if req.args.has_key("parse"):
                        ret = autotimer.parseEPG()
                        output = _("Found a total of %d matching Events.\n%d Timer were added and %d modified.") % (ret[0], ret[1], ret[2])
+                       res = True
                else:
                        output = "unknown command"
 
                if remove:
+                       autotimer.writeXml()
                        autotimer = None
-               return http.Response(responsecode.OK ,stream = output)
+
+               result = """<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n
+                       <e2simplexmlresult>\n
+                               <e2state>%s</e2state>\n
+                               <e2statetext>%s</e2statetext>\n
+                       </e2simplexmlresult>
+                       """ % ('true' if res else 'false', output)
+
+               XML_HEADER = {'Content-type': http_headers.MimeType('application', 'xhtml+xml', (('charset', 'UTF-8'),))}
+               return http.Response(responsecode.OK, XML_HEADER, stream = result)
 
index 72d5d24..21e93b4 100644 (file)
@@ -1,4 +1,4 @@
-from twisted.web2 import resource, responsecode, http
+from twisted.web2 import http, http_headers, resource, responsecode
 from EPGRefresh import epgrefresh
 
 # pretty basic resource which is just present to have a way to start a
@@ -8,12 +8,23 @@ class EPGRefreshResource(resource.Resource):
                resource.Resource.__init__(self)
 
        def render(self, req):
+               res = False
                if req.args.has_key("refresh"):
                        if epgrefresh.forceRefresh():
                                output = "initiated refresh"
+                               res = True
                        else:
                                output = "could not initiate refresh"
                else:
                        output = "unknown command"
-               return http.Response(responsecode.OK, stream = output)
+
+               result = """<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n
+                       <e2simplexmlresult>\n
+                               <e2state>%s</e2state>\n
+                               <e2statetext>%s</e2statetext>\n
+                       </e2simplexmlresult>
+                       """ % ('true' if res else 'false', output)
+
+               XML_HEADER = {'Content-type': http_headers.MimeType('application', 'xhtml+xml', (('charset', 'UTF-8'),))}
+               return http.Response(responsecode.OK, XML_HEADER, stream = result)