[kupfer] plugin_support: Conveniece function to check for D-Bus
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] plugin_support: Conveniece function to check for D-Bus
- Date: Fri, 27 Nov 2009 13:13:43 +0000 (UTC)
commit 51b103649a5634de7ef9eebf76e2766537146f43
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Nov 27 14:06:39 2009 +0100
plugin_support: Conveniece function to check for D-Bus
"""
Check if a connection to the D-Bus daemon is available,
else raise ImportError with an explanatory error message.
For plugins that can not be used without contact with D-Bus;
if this check is used, the plugin may use D-Bus and assume it
is available in the Plugin's code.
"""
kupfer/plugin_support.py | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin_support.py b/kupfer/plugin_support.py
index 5c17274..c82b098 100644
--- a/kupfer/plugin_support.py
+++ b/kupfer/plugin_support.py
@@ -79,3 +79,29 @@ class PluginSettings (pretty.OutputMixin):
def get_tooltip(self, key):
"""Return tooltip string for setting @key (if any)"""
return self.setting_descriptions[key].get("tooltip")
+
+# Plugin convenience functions for dependencies
+
+_has_dbus_connection = None
+
+def check_dbus_connection():
+ """
+ Check if a connection to the D-Bus daemon is available,
+ else raise ImportError with an explanatory error message.
+
+ For plugins that can not be used without contact with D-Bus;
+ if this check is used, the plugin may use D-Bus and assume it
+ is available in the Plugin's code.
+ """
+ global _has_dbus_connection
+ if _has_dbus_connection is None:
+ import dbus
+ try:
+ dbus.Bus()
+ _has_dbus_connection = True
+ except dbus.DBusException, err:
+ _has_dbus_connection = False
+ if not _has_dbus_connection:
+ raise ImportError(_("No D-Bus connection to desktop session"))
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]