[Sugar-devel] [Read PATCH v2] don't break if HAL is not available

Sascha Silbe sascha-pgp at silbe.org
Thu Jun 17 16:27:50 EDT 2010


HAL is only used for displaying the current battery status, so it's
entirely optional.
---
 readtopbar.py |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

v1->v2: log warning when HAL is unavailable

diff --git a/readtopbar.py b/readtopbar.py
index 3f338f5..cca68e2 100644
--- a/readtopbar.py
+++ b/readtopbar.py
@@ -134,17 +134,22 @@ class _TopBar(gtk.HBox):
         self._completion_level = 0
         self._progressbar = None
 
-        bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
-        proxy = bus.get_object('org.freedesktop.Hal',
-                                '/org/freedesktop/Hal/Manager')
-        hal_manager = dbus.Interface(proxy, 'org.freedesktop.Hal.Manager')
-        udis = hal_manager.FindDeviceByCapability('battery')
-        if len(udis) > 0:
-            self._battery = BattMan(udis[0]) # TODO: Support more than one battery
-            self._battery.connect('notify::level', \
-                self._battery_level_changed_cb)
-        else:
-            self._battery = None
+
+        self._battery = None
+        try:
+            bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
+            proxy = bus.get_object('org.freedesktop.Hal',
+                                    '/org/freedesktop/Hal/Manager')
+            hal_manager = dbus.Interface(proxy, 'org.freedesktop.Hal.Manager')
+            udis = hal_manager.FindDeviceByCapability('battery')
+            if len(udis) > 0:
+                self._battery = BattMan(udis[0]) # TODO: Support more than one battery
+                self._battery.connect('notify::level', \
+                    self._battery_level_changed_cb)
+
+        except dbus.DBusException:
+            logging.warning('HAL not found. Will not be able to display'
+                ' battery charge level.')
 
         self._icon = None
 
-- 
1.6.5



More information about the Sugar-devel mailing list