show error message when loading the page url feed fails
authorChristian Weiske <cweiske@cweiske.de>
Fri, 2 Dec 2011 16:34:38 +0000 (17:34 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 2 Dec 2011 16:34:38 +0000 (17:34 +0100)
src/AtomFeed.py
src/CurlyTxSettings.py

index 2a9f55d..9e76e9f 100644 (file)
@@ -9,16 +9,12 @@ from xml.etree.cElementTree import fromstring
 class AtomFeed:
     """ Simple XML parser that extracts pages from a atom feed """
     ns = "{http://www.w3.org/2005/Atom}"
-    def __init__(self, url, callback):
+    def __init__(self, url, callback, errorCallback):
         """ Fetches the URL
 
         Parsed pages are sent back to callback by parse()
         """
-        getPage(url).addCallback(self.parse, callback).addErrback(self.fail)
-
-
-    def fail(self, msg):
-        print("CurlyTx", msg)
+        getPage(url).addCallback(self.parse, callback).addErrback(errorCallback)
 
     def parse(self, data, callback):
         """ Parse atom feed data into pages list and run callback """
index f733e12..c04acb2 100644 (file)
@@ -134,7 +134,10 @@ class CurlyTxSettings(ConfigListScreen, HelpableScreen, Screen):
                 )
         elif config.plugins.CurlyTx.feedUrl.value:
             from AtomFeed import AtomFeed
-            AtomFeed(config.plugins.CurlyTx.feedUrl.value, self.feedPagesReceived)
+            AtomFeed(
+                config.plugins.CurlyTx.feedUrl.value,
+                self.feedPagesReceived, self.feedPagesFail
+                )
         else:
             self.session.open(
                 MessageBox, _("No page feed URL defined"), MessageBox.TYPE_ERROR
@@ -163,6 +166,14 @@ class CurlyTxSettings(ConfigListScreen, HelpableScreen, Screen):
 
         self["config"].setList(self.getConfigList())
 
+    def feedPagesFail(self, failure):
+        """ Downloading the page url feed failed somehow """
+        self.session.open(
+            MessageBox,
+            _("Error loading page feed:") + "\n\n" + str(failure.getErrorMessage()),
+            MessageBox.TYPE_ERROR
+            )
+
     def keySave(self):
         for i in range(0, len(config.plugins.CurlyTx.pages)):
             config.plugins.CurlyTx.pages[i].save()