Source

pida-patches / non-optional-core-pdbus

# HG changeset patch
# Parent 0096dcc07322905f9aa64fe328da5299ec627195
make dbus non-optional

diff --git a/pida/core/pdbus.py b/pida/core/pdbus.py
--- a/pida/core/pdbus.py
+++ b/pida/core/pdbus.py
@@ -22,57 +22,38 @@ from pango import Font
 from pygtkhelpers.gthreads import gcall
 from pida.core.environment import workspace_name
 
-try:
-    import dbus
+import dbus
+has_dbus=True
 
-    from dbus.lowlevel import SignalMessage
-    from dbus.mainloop.glib import DBusGMainLoop
-    DBusMainloop = DBusGMainLoop(set_as_default=True)
+from dbus.lowlevel import SignalMessage
+from dbus.mainloop.glib import DBusGMainLoop
+DBusMainloop = DBusGMainLoop(set_as_default=True)
 
-    from dbus.service import (Object, INTROSPECTABLE_IFACE, _method_reply_error,
-        _method_reply_return)
-    from dbus.service import method, signal
-    from dbus import Signature
-    import _dbus_bindings
+from dbus.service import (Object, INTROSPECTABLE_IFACE, _method_reply_error,
+    _method_reply_return)
+from dbus.service import method, signal
+from dbus import Signature
+import _dbus_bindings
 
-    # Is dbus available?
-    # Throws dbus.exceptions.DBusException if not.
-    #XXX:
-    try:
-        BUS_NAME = dbus.service.BusName(
-                'uk.co.pida.pida.p%s' % os.getpid(),
-                bus=dbus.SessionBus())
-        has_dbus = True
-    except dbus.exceptions.DBusException:
-        has_dbus = False
+# Is dbus available?
+# Throws dbus.exceptions.DBusException if not.
 
-except ImportError:
-    def dummy(*k, **kw):
-        return lambda x: x
-    method = signal = dummy
-    INTROSPECTABLE_IFACE = ""
-    has_dbus = False
-    Object = object
+BUS_NAME = dbus.service.BusName(
+        'uk.co.pida.pida.p%s' % os.getpid(),
+        bus=dbus.SessionBus())
 
-class DbusConfigReal(Object):
+
+class DbusConfig(Object):
 
     def __init__(self, service):
         self.svc = service
-        if hasattr(self, 'export_name'):
-            path = DBUS_PATH(self.export_name)
-            ns = DBUS_NS(self.export_name)
-        else:
-            path = DBUS_PATH(service.get_name())
-            ns = DBUS_NS(service.get_name())
+        path = DBUS_PATH(service.get_name())
+        ns = DBUS_NS(service.get_name())
         self.dbus_ns = ns
         Object.__init__(self, BUS_NAME, path)
 
-class DbusConfigNoop(object):
 
-    def __init__(self, service):
-        pass
-
-class DbusOptionsManagerReal(Object):
+class DbusOptionsManager(Object):
     __dbus_mapping = {
         bool: 'b',
         str: 's',
@@ -89,12 +70,8 @@ class DbusOptionsManagerReal(Object):
 
     def __init__(self, service):
         self.svc = service
-        if hasattr(self, 'export_name'):
-            path = DBUS_PATH(self.export_name, self.dbus_path)
-            ns = DBUS_NS(self.export_name, self.dbus_path)
-        else:
-            path = DBUS_PATH(service.get_name(), self.dbus_path)
-            ns = DBUS_NS(service.get_name(), self.dbus_path)
+        path = DBUS_PATH(service.get_name(), self.dbus_path)
+        ns = DBUS_NS(service.get_name(), self.dbus_path)
         self.dbus_ns = ns
         self.dbus_path = path
         Object.__init__(self, BUS_NAME, path)
@@ -243,7 +220,7 @@ class DbusOptionsManagerReal(Object):
                  method_name == 'CONFIG_EXTRA_CHANGED':
                     return
         # do a normal lookup
-        return super(DbusOptionsManagerReal, self)._message_cb(connection, message)
+        return super(DbusOptionsManager, self)._message_cb(connection, message)
 
     @method(INTROSPECTABLE_IFACE, in_signature='', out_signature='s',
             path_keyword='object_path', connection_keyword='connection')
@@ -275,56 +252,13 @@ class DbusOptionsManagerReal(Object):
 
 
 
-class DbusOptionsManagerNoop(object):
+from pida.utils.pdbus import (UUID, DBUS_PATH, DBUS_NS, EXPORT,
+    SIGNAL, BUS)
+from dbus.mainloop.glib import DBusGMainLoop
 
-    def __init__(self, service):
-        pass
+DBusMainloop = DBusGMainLoop(set_as_default=True)
 
-    def unload(self):
-        pass
 
-    def notify_dbus(self, *args):
-        pass
+# export the PIDA UUID to the environment for
 
-    def export_option(self, option):
-        pass
-
-    def export_action(self, action):
-        pass
-
-if has_dbus:
-
-    from pida.utils.pdbus import (UUID, DBUS_PATH, DBUS_NS, EXPORT,
-        SIGNAL, BUS)
-    from dbus.mainloop.glib import DBusGMainLoop
-
-    DBusMainloop = DBusGMainLoop(set_as_default=True)
-
-
-    # export the PIDA UUID to the environment for
-
-    os.environ['PIDA_DBUS_UUID'] = UUID
-
-    DbusConfig = DbusConfigReal
-    DbusOptionsManager = DbusOptionsManagerReal
-else:
-    # noop DbusConfig
-    def noop(*args, **kwargs):
-        return []
-
-    def nowrapper(*args, **kwargs):
-        def wrapper(*args, **kwargs):
-            def noop(func, *k, **kw):
-                return func
-            return noop
-        return wrapper
-
-    UUID = None
-    DBUS_PATH = noop
-    DBUS_NS = noop
-    EXPORT = nowrapper
-    SIGNAL = nowrapper
-    BUS_NAME = None
-    BUS = None
-    DbusConfig = DbusConfigNoop
-    DbusOptionsManager = DbusOptionsManagerNoop
+os.environ['PIDA_DBUS_UUID'] = UUID