From 9601ba132307b4c879eb7be7a4dddcde6f98b716 Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Wed, 29 Mar 2017 23:30:23 +0200 Subject: [PATCH] python: catch more DBus exceptions Gio.bus_get_sync may return None when the DBus service is not available (see libratbag/piper#2). In addition to this, the service may time out when it is being started in which case Gio.DBusProxy.new_sync will raise a GLib.Gerror. This commit checks for both scenarios and raises a RatbagdDBusUnavailable exception when either one of them occurs. This will in turn be caught in for example Piper to properly deal with this. --- python/ratbagd/__init__.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/python/ratbagd/__init__.py b/python/ratbagd/__init__.py index 3df5766..6fa70c1 100644 --- a/python/ratbagd/__init__.py +++ b/python/ratbagd/__init__.py @@ -35,13 +35,20 @@ class RatbagdDBusUnavailable(BaseException): class _RatbagdDBus(object): def __init__(self, interface, object_path): self._dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) - self._proxy = Gio.DBusProxy.new_sync(self._dbus, - Gio.DBusProxyFlags.NONE, - None, - 'org.freedesktop.ratbag1', - object_path, - 'org.freedesktop.ratbag1.{}'.format(interface), - None) + if self._dbus is None: + raise RatbagdDBusUnavailable() + + try: + self._proxy = Gio.DBusProxy.new_sync(self._dbus, + Gio.DBusProxyFlags.NONE, + None, + 'org.freedesktop.ratbag1', + object_path, + 'org.freedesktop.ratbag1.{}'.format(interface), + None) + except GLib.GError: + raise RatbagdDBusUnavailable() + if self._proxy.get_name_owner() == None: raise RatbagdDBusUnavailable() @@ -60,6 +67,8 @@ class Ratbagd(_RatbagdDBus): The ratbagd top-level object. Provides a list of devices available through ratbagd, actual interaction with the devices is via the RatbagdDevice, RatbagdProfile and RatbagdResolution objects. + + Throws RatbagdDBusUnavailable when the DBus service is not available. """ def __init__(self): _RatbagdDBus.__init__(self, "Manager", '/org/freedesktop/ratbag1')