summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Minack <enrico-minack@gmx.de>2010-07-06 13:54:14 +0200
committerEnrico Minack <enrico-minack@gmx.de>2010-07-06 13:54:14 +0200
commit6121f5b9a6438bfde3e0da3a9920827d3a75344b (patch)
tree69d28c211865da9d37987ede52a8e112a5f3f576
parentdf51669c1dfee18cc1a487b1240f862083bdac38 (diff)
[invest-applet] handles exception when gconfd is not available, fixes bug #615662
GConfd might not yet be available when Gnome starts. Until now, this caused the invest applet to crash. This fix makes the applet wait some seconds and retry, in case GConfd will be available soon.
-rw-r--r--invest-applet/invest/__init__.py65
1 files changed, 45 insertions, 20 deletions
diff --git a/invest-applet/invest/__init__.py b/invest-applet/invest/__init__.py
index 63cc9dd69..c642bbd5f 100644
--- a/invest-applet/invest/__init__.py
+++ b/invest-applet/invest/__init__.py
@@ -120,34 +120,59 @@ except Exception, msg:
# },
#}
-client = gconf.client_get_default()
+# set default proxy config
+PROXY = None
# borrowed from Ross Burton
# http://burtonini.com/blog/computers/postr
+# extended by exception handling and retry scheduling
def get_gnome_proxy(client):
- if client.get_bool("/system/http_proxy/use_http_proxy"):
- host = client.get_string("/system/http_proxy/host")
- port = client.get_int("/system/http_proxy/port")
- if host is None or host == "" or port == 0:
- # gnome proxy is not valid, use enviroment if available
- return None
-
- if client.get_bool("/system/http_proxy/use_authentication"):
- user = client.get_string("/system/http_proxy/authentication_user")
- password = client.get_string("/system/http_proxy/authentication_password")
- if user and user != "":
- url = "http://%s:%s@%s:%d" % (user, password, host, port)
+ sleep = 10 # sleep between attempts for 10 seconds
+ attempts = 3 # try to get configuration from gconf at most three times
+ get_gnome_proxy_retry(client, attempts, sleep)
+
+def get_gnome_proxy_retry(client, attempts, sleep):
+ # decrease attempts counter
+ attempts -= 1
+
+ # sanity check if we still need to look for proxy configuration
+ global PROXY
+ if PROXY != None:
+ return
+
+ # try to get config from gconfd
+ try:
+ if client.get_bool("/system/http_proxy/use_http_proxy"):
+ host = client.get_string("/system/http_proxy/host")
+ port = client.get_int("/system/http_proxy/port")
+ if host is None or host == "" or port == 0:
+ # gnome proxy is not valid, stop here
+ return
+
+ if client.get_bool("/system/http_proxy/use_authentication"):
+ user = client.get_string("/system/http_proxy/authentication_user")
+ password = client.get_string("/system/http_proxy/authentication_password")
+ if user and user != "":
+ url = "http://%s:%s@%s:%d" % (user, password, host, port)
+ else:
+ url = "http://%s:%d" % (host, port)
else:
url = "http://%s:%d" % (host, port)
- else:
- url = "http://%s:%d" % (host, port)
- return {'http': url}
- else:
- # gnome proxy is not set, use enviroment if available
- return None
+ # proxy config found, memorize
+ PROXY = {'http': url}
+
+ except Exception, msg:
+ error("Failed to get proxy configuration from GConfd:\n%s" % msg)
+ # we did not succeed, schedule retry
+ if attempts > 0:
+ error("Retrying to contact GConfd in %d seconds" % sleep)
+ gobject.timeout_add(sleep * 1000, get_gnome_proxy_retry, client, attempts, sleep)
+
+# use gconf to get proxy config
+client = gconf.client_get_default()
+get_gnome_proxy(client)
-PROXY = get_gnome_proxy(client)
# connect to Network Manager to identify current network connectivity
nm = networkmanager.NetworkManager()