[Sugar-devel] [PATCH GetBooks] Report when could not reach the server SL #3180

Manuel Kaufmann humitos at gmail.com
Wed May 16 08:48:51 EDT 2012


Handled urllib2.URLError returned by feedparser to inform the user
about this problem, saying that maybe he is not connected to the
network.

If there were another problem downloading the list, the user is
informed with a generic message.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 GetIABooksActivity.py |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py
index 0a06069..bc132f9 100644
--- a/GetIABooksActivity.py
+++ b/GetIABooksActivity.py
@@ -20,6 +20,8 @@ import os
 import logging
 import time
 import gtk
+import urllib2
+import socket
 
 OLD_TOOLBAR = False
 try:
@@ -798,7 +800,18 @@ class GetIABooksActivity(activity.Activity):
 
     def __query_updated_cb(self, query, midway):
         self.listview.populate(self.queryresults)
-        if (len(self.queryresults.get_catalog_list()) > 0):
+        if 'bozo_exception' in self.queryresults._feedobj:
+            # something went wrong and we have to inform about this
+            bozo_exception = self.queryresults._feedobj.bozo_exception
+            if isinstance(bozo_exception, urllib2.URLError):
+                if isinstance(bozo_exception.reason, socket.gaierror):
+                    if bozo_exception.reason.errno == -2:
+                        self.show_message(_('Could not reach the server. '
+                            'Maybe you are not connected to the network'))
+                        self.window.set_cursor(None)
+                        return
+            self.show_message(_('There was an error downloading the list.'))
+        elif (len(self.queryresults.get_catalog_list()) > 0):
             self.show_message(_('New catalog list %s was found') \
                 % self.queryresults._configuration["name"])
             self.catalogs_updated(query, midway)
-- 
1.7.10



More information about the Sugar-devel mailing list