From 6b7f36ebd1d30abeb642ae1a099d01476820146c Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 8 Dec 2009 14:45:58 +0100 Subject: [PATCH] prevent traceback when geoclue not installed. Fixes #5495 --- src/common/location_listener.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/common/location_listener.py b/src/common/location_listener.py index ae5373447..f1ba5b714 100644 --- a/src/common/location_listener.py +++ b/src/common/location_listener.py @@ -43,7 +43,7 @@ class LocationListener: def _get_address(self): bus = dbus.SessionBus() if 'org.freedesktop.Geoclue.Master' not in bus.list_names(): - self._on_geoclue_address_changed(0, {}, 0) + self._on_geoclue_address_changed() return obj = bus.get_object('org.freedesktop.Geoclue.Master', '/org/freedesktop/Geoclue/Master') @@ -61,7 +61,7 @@ class LocationListener: def _get_position(self): bus = dbus.SessionBus() if 'org.freedesktop.Geoclue.Master' not in bus.list_names(): - self._on_geoclue_position_changed([], 0, None, None, 0) + self._on_geoclue_position_changed() return obj = bus.get_object('org.freedesktop.Geoclue.Master', '/org/freedesktop/Geoclue/Master') @@ -89,25 +89,31 @@ class LocationListener: def shut_down(self): pass - def _on_geoclue_address_changed(self, timestamp, address, accuracy): + def _on_geoclue_address_changed(self, timestamp=None, address={}, + accuracy=None): # update data with info we just received for field in ['country', 'countrycode', 'locality', 'postalcode', 'region', 'street']: self._data[field] = address.get(field, None) - self._data['timestamp'] = timestamp - # in PEP it's horizontal accuracy - self._data['accuracy'] = accuracy[1] + if timestamp: + self._data['timestamp'] = timestamp + if accuracy: + # in PEP it's horizontal accuracy + self._data['accuracy'] = accuracy[1] self._send_location() - def _on_geoclue_position_changed(self, fields, timestamp, lat, lon, alt, - accuracy): + def _on_geoclue_position_changed(self, fields=[], timestamp=None, lat=None, + lon=None, alt=None, accuracy=None): # update data with info we just received _dict = {'lat': lat, 'lon': lon, 'alt': alt} for field in _dict: - self._data[field] = _dict[field] - self._data['timestamp'] = timestamp - # in PEP it's horizontal accuracy - self._data['accuracy'] = accuracy[1] + if _dict[field] is not None: + self._data[field] = _dict[field] + if timestamp: + self._data['timestamp'] = timestamp + if accuracy: + # in PEP it's horizontal accuracy + self._data['accuracy'] = accuracy[1] self._send_location() def _send_location(self):