Commits

Ronny Pfannschmidt  committed b739e91

update to latest state

  • Participants
  • Parent commits 32f01aa

Comments (0)

Files changed (9)

File core-pdbus-pyxml-introspect

+# HG changeset patch
+# Parent 13caa9200d349dff5052e68fd7ea070af71ea835
+use py.xml to generate the dbus introspection metadata
+
+diff --git a/pida/core/pdbus.py b/pida/core/pdbus.py
+--- a/pida/core/pdbus.py
++++ b/pida/core/pdbus.py
+@@ -11,6 +11,13 @@
+ 
+ 
+ import os
++
++import py
++
++
++class ns(py.xml.Namespace):
++    "namespace for introspection"
++
+ from pango import Font
+ from pygtkhelpers.gthreads import gcall
+ from pida.core.environment import workspace_name
+@@ -169,21 +176,20 @@ class DbusOptionsManagerReal(Object):
+             raise ValueError, "No object type found for %s" % type_
+ 
+     def dbus_custom_introspect(self):
+-        rv = '  <interface name="%s">\n' % (self.dbus_ns)
++        rv = ns.interface(name=self.dbus_ns)
+         for option in self._options.itervalues():
+             try:
+-                typ = self.object_to_dbus(option.type)
++                type_sig = self.object_to_dbus(option.type)
+             except ValueError, e:
+                 print "Can't find conversation dbus conversation for ", option
+                 continue
+-            rv += '    <property name="%s" type="%s" access="readwrite"/>\n' % (option.name, typ)
++            rv.append(ns.property(name=option.name, type=type_sig, access="readwrite"))
+ 
+         if hasattr(self, '_actions'):
+             for action in self._actions.list_actions():
+                 if action.get_name() not in self.dbus_no_activate:
+-                    rv += '    <method name="activate_%s" />\n' % (action.get_name())
++                    rv.append(ns.method(name='activate_%s' % action.get_name()))
+ 
+-        rv += '  </interface>\n'
+         return rv
+ 
+     def _message_cb(self, connection, message):
+@@ -245,29 +251,28 @@ class DbusOptionsManagerReal(Object):
+         """Return a string of XML encoding this object's supported interfaces,
+         methods and signals.
+         """
+-        reflection_data = _dbus_bindings.DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
+-        reflection_data += '<node name="%s">\n' % object_path
++        #reflection_data = _dbus_bindings.DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
++        reflection_data = ns.node(name=object_path)
+ 
+         interfaces = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__]
+         for (name, funcs) in interfaces.iteritems():
+-            reflection_data += '  <interface name="%s">\n' % (name)
++            interface = ns.interface(name=name)
++            reflection_data.append(interface)
+ 
+             for func in funcs.values():
+                 if getattr(func, '_dbus_is_method', False):
+-                    reflection_data += self.__class__._reflect_on_method(func)
++                    interface.append(py.xml.raw(self.__class__._reflect_on_method(func)))
+                 elif getattr(func, '_dbus_is_signal', False):
+-                    reflection_data += self.__class__._reflect_on_signal(func)
++                    interface.append(py.xml.raw(self.__class__._reflect_on_signal(func)))
+ 
+-            reflection_data += '  </interface>\n'
+ 
+-        reflection_data += self.dbus_custom_introspect()
++        reflection_data.append(self.dbus_custom_introspect())
+ 
+         for name in connection.list_exported_child_objects(object_path):
+-            reflection_data += '  <node name="%s"/>\n' % name
++            reflection_data.append(ns.node(name=name))
+ 
+-        reflection_data += '</node>\n'
++        return reflection_data.unicode()
+ 
+-        return reflection_data
+ 
+ 
+ class DbusOptionsManagerNoop(object):

File error-free-plugin-load

-# HG changeset patch
-# User Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
-# Date 1243750351 -7200
-# Node ID f5add93dc7e0c15ee944adbc355db520dcf53737
-# Parent  3b88bb1b40d299ed4e522933af9856a3b4bca346
-initial handler for graccefull handling of plugin loading errors NEEDS TESTS
-
-diff -r 3b88bb1b40d2 -r f5add93dc7e0 pida/core/servicemanager.py
---- a/pida/core/servicemanager.py	Wed Jun 10 04:08:16 2009 +0200
-+++ b/pida/core/servicemanager.py	Sun May 31 08:12:31 2009 +0200
-@@ -139,23 +139,48 @@ class ServiceManager(object):
-         self._pre_start_services()
- 
-     def start_plugin(self, name):
--        plugin = self._plugins.get_one(name)(self._boss)
--        assert not hasattr(plugin, 'started')
--        plugin.started = False # not yet started
--        pixmaps_dir = os.path.join(plugin.__path__, 'pixmaps')
--        if os.path.exists(pixmaps_dir):
--            self._boss._icons.register_file_icons_for_directory(pixmaps_dir)
--        if plugin is not None:
-+        plugin_class = self._plugins.get_one(name)
-+        if plugin_class is None:
-+            log.error('Unable to load plugin %s' % name)
-+            return
-+
-+        #XXX: test this more roughly
-+        plugin = plugin_class(self._boss)
-+        try:
-+            if hasattr(plugin, 'started') :
-+                log.error("plugin.started shouldn't be set by %r", plugin)
-+
-+            plugin.started = False # not yet started
-+
-+            #XXX: unregister?
-+            pixmaps_dir = os.path.join(plugin.__path__, 'pixmaps')
-+            if os.path.exists(pixmaps_dir):
-+                self._boss._icons.register_file_icons_for_directory(pixmaps_dir)
-             self._register(plugin)
--            plugin.create_all()
--            plugin.subscribe_all()
--            plugin.pre_start()
--            plugin.start()
--            assert plugin.started is False # this shouldn't change
--            plugin.started = True
--            return plugin
--        else:
--            log.error('Unable to load plugin %s' % name)
-+            try:
-+                try:
-+                    plugin.create_all()
-+
-+                    #stop_components will handle
-+                    plugin.subscribe_all()
-+
-+                    #XXX: what to do with unrolling those
-+                    plugin.pre_start()
-+                    plugin.start()
-+                    assert plugin.started is False # this shouldn't change
-+                    plugin.started = True
-+                    return plugin
-+                except:
-+                    plugin.stop_components()
-+                    raise
-+            except:
-+                del self._reg[name]
-+                raise
-+
-+        except:
-+            self._plugins.unload(name)
-+            raise
-+
- 
-     def stop_plugin(self, name):
-         plugin = self.get_service(name)

File 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

File reenable-dbus-support

+# HG changeset patch
+# Parent 402342fcfc30bf2028feff9756e66c386d229f62
+diff --git a/pida/core/actions.py b/pida/core/actions.py
+--- a/pida/core/actions.py
++++ b/pida/core/actions.py
+@@ -83,6 +83,7 @@ class ActionsConfig(OptionsConfig):
+     name = '%s.keys.json'
+     accelerator_group = accelerator_group
+     global_accelerator_group = global_accelerator_group
++    dbus_path = 'actions'
+ 
+     def create(self):
+         """
+diff --git a/pida/core/options.py b/pida/core/options.py
+--- a/pida/core/options.py
++++ b/pida/core/options.py
+@@ -26,6 +26,7 @@ from shutil import rmtree
+ 
+ from .base import BaseConfig
+ from .environment import is_safe_mode, killsettings, settings_dir
++from .pdbus import DbusOptionsManager
+ # locale
+ from pida.core.locale import Locale
+ locale = Locale('core')
+@@ -194,14 +195,16 @@ class ExtraOptionItem(object):
+ 
+ manager = OptionsManager()
+ 
+-class OptionsConfig(BaseConfig):
++class OptionsConfig(BaseConfig, DbusOptionsManager):
+ 
+     #enable reuse for keyboard shortcuts that need different name
+     name = '%s.json'
+     name_extra = "%s_extra_%s.json"
++    dbus_path = 'options'
+ 
+     def __init__(self, service, *args, **kwargs):
+         BaseConfig.__init__(self, service, *args, **kwargs)
++        DbusOptionsManager.__init__(self, service)
+ 
+ 
+     def unload(self):

File remove-extra-match-signal-handler

+# HG changeset patch
+# Parent d76042a64bb3f751160d89cdef6bc7cf9feb6772
+also remove the extra option match signal handler
+
+diff --git a/pida/core/pdbus.py b/pida/core/pdbus.py
+--- a/pida/core/pdbus.py
++++ b/pida/core/pdbus.py
+@@ -85,6 +85,7 @@ class DbusOptionsManager(Object):
+ 
+     def unload(self):
+         self.config_match.remove()
++        self.config_extra_match.remove()
+         self.remove_from_connection()
+ 
+     def on_config_changed(self, workspace, name, value, sender=None):
-error-free-plugin-load
-waypoint
+uil-pdbus-cleanup
+core-pdbus-pyxml-introspect
+non-optional-core-pdbus #-dbus
+remove-extra-match-signal-handler
+test-workpsace-window #-dbus
+reenable-dbus-support

File test-workpsace-window

+# HG changeset patch
+# Parent 018d5f93ed1f076609902cc5871148d786e5bebe
+test workspace window
+
+diff --git a/tests/ui/test_window.py b/tests/ui/test_window.py
+--- a/tests/ui/test_window.py
++++ b/tests/ui/test_window.py
+@@ -1,7 +1,7 @@
+ 
+ from pida.utils.testing import refresh_gui
+ from pida.utils.testing.mock import Mock
+-from pida.ui.window import PidaWindow
++from pida.ui.window import PidaWindow, WorkspaceWindow
+ from pida.core.boss import Boss
+ from pida.services.window.window import Window as WindowSvc
+ 
+@@ -33,4 +33,12 @@ def test_svc_setup(boss, monkeypatch, tm
+     svc.save_state()
+ 
+ 
++from pida.core import options
++from pida.utils import pdbus
+ 
++def test_workspace_window(monkeypatch):
++    monkeypatch.setattr(pdbus, 'list_pida_instances', lambda **kw: None)
++    monkeypatch.setattr(options, 'list_workspaces', lambda: ['default'])
++    w = WorkspaceWindow()
++    refresh_gui()
++    

File uil-pdbus-cleanup

+# HG changeset patch
+# Parent a1525b07592d201ee8e97e7d8ed04086a2b68458
+small code cleanup in util.pdbus
+
+diff --git a/pida/utils/pdbus.py b/pida/utils/pdbus.py
+--- a/pida/utils/pdbus.py
++++ b/pida/utils/pdbus.py
+@@ -13,7 +13,7 @@ from dbus.lowlevel import MethodCallMess
+ from json import loads
+ 
+ DBUS_NS_PREFIX = 'uk.co.pida.pida'
+-DBUS_PATH_PREFIX = '/uk/co/pida/pida'
++DBUS_PATH_PREFIX = '/uk/co/pida/pida',
+ 
+ BUS = dbus.SessionBus()
+ UUID = "p" + str(os.getpid())
+@@ -22,7 +22,7 @@ def DBUS_NS(*path):
+     return ".".join((DBUS_NS_PREFIX, ) + path)
+ 
+ def DBUS_PATH(*path, **kwargs):
+-    return "/".join((DBUS_PATH_PREFIX,) + path)
++    return "/".join(DBUS_PATH_PREFIX + path)
+ 
+ 
+ def _dbus_decorator(f, ns=None, suffix=None):
+@@ -44,11 +44,6 @@ def _dbus_decorator(f, ns=None, suffix=N
+ EXPORT = partial(_dbus_decorator, dbus.service.method)
+ SIGNAL = partial(_dbus_decorator, dbus.service.signal)
+ 
+-def rec_pida_pong(*args):
+-    global _ACTIVE_PIDAS
+-    _ACTIVE_PIDAS[str(args[0])] = args
+-
+-
+ 
+ def list_pida_bus_names(include_self=False):
+     session = dbus.SessionBus()
+@@ -70,7 +65,7 @@ def list_pida_instances(include_this=Fal
+     result = []
+     for name in pida_names:
+         #XXX: this is sync, that may be evil
+-        # we asume that only active and 
++        # we asume that only active and
+         # working instances expose the object
+         try:
+             app = session.get_object(

File waypoint

-diff -r f5add93dc7e0 pida-plugins/waypoint/test_waypoint.py
---- a/pida-plugins/waypoint/test_waypoint.py	Sun May 31 08:12:31 2009 +0200
-+++ b/pida-plugins/waypoint/test_waypoint.py	Wed Jun 10 14:58:01 2009 +0200
-@@ -26,10 +26,12 @@ from pida.core.document import Document
- 
- from .waypoint import WayPoint, WayStack
- 
--BOSS = Mock()
- 
- class WaypointTest(object):
- 
-+    def setup_method(self, method):
-+        self.boss = Mock()
-+
-     def should(self, wp, should):
-         for i, (doc, pos) in enumerate(should):
-             self.assertEqual(wp[i].document, doc)
-@@ -37,8 +39,8 @@ class WaypointTest(object):
- 
- 
-     def test_has(self):
--        doc1 = Document(BOSS)
--        doc2 = Document(BOSS)
-+        doc1 = Document(self.boss)
-+        doc2 = Document(self.boss)
-         wp = WayStack(max_length=10, threshold=10)
-         w1 = WayPoint(doc1, 10)
-         w2 = WayPoint(doc1, 10)
-@@ -73,7 +75,7 @@ class WaypointTest(object):
-         w3 = WayPoint(doc2, 10)
- 
-     def test_maxlength(self):
--        doc1 = Document(BOSS)
-+        doc1 = Document(self.boss)
-         wp = WayStack(max_length=10, threshold=10, timespan=5)
-         for i in xrange(20):
-             wp.notify_change(doc1, 100*i+1, time_=(60*i)+1)
-@@ -84,8 +86,8 @@ class WaypointTest(object):
- 
- 
-     def test_waypoint(self):
--        doc1 = Document(BOSS)
--        doc2 = Document(BOSS)
-+        doc1 = Document(self.boss)
-+        doc2 = Document(self.boss)
-         wp = WayStack(max_length=10, threshold=30, timespan=4)
-         wp.notify_change(doc1, 10, time_=10)
-         wp.notify_change(doc1, 12, time_=20)
-@@ -146,8 +148,8 @@ class WaypointTest(object):
- 
- 
-     def test_waypoint_jump(self):
--        doc1 = Document(BOSS)
--        doc2 = Document(BOSS)
-+        doc1 = Document(self.boss)
-+        doc2 = Document(self.boss)
-         wp = WayStack(max_length=10)
-         wp.notify_change(doc1, 10, time_=10)
-         wp.notify_change(doc1, 10, time_=20)