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

Sascha Silbe sascha-pgp at silbe.org
Wed Jun 16 18:22:56 EDT 2010


HAL is only used for displaying the current battery status, so it's
entirely optional.

Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>
---
 readtopbar.py |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/readtopbar.py b/readtopbar.py
index 3f338f5..b891afe 100644
--- a/readtopbar.py
+++ b/readtopbar.py
@@ -134,17 +134,21 @@ 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:
+            pass
 
         self._icon = None
 
-- 
1.6.5



More information about the Sugar-devel mailing list