LEW21 / pydbus

Pythonic DBus library
GNU Lesser General Public License v2.1
331 stars 75 forks source link

Can't run inside a docker container. #70

Open psukys opened 6 years ago

psukys commented 6 years ago

When trying to run through dbus-session-run python dbus_endpoint.py, I get the following error:

  File "dbus_endpoint.py", line 39, in <module>
    bus.publish(dbus_path, DbusEndpoint(dbus_path))
  File "/usr/local/lib/python2.7/dist-packages/pydbus/publication.py", line 42, in publish
    return Publication(self, bus_name, *objects)
  File "/usr/local/lib/python2.7/dist-packages/pydbus/publication.py", line 32, in __init__
    self._at_exit(bus.register_object(path, object, node_info).__exit__)
  File "/usr/local/lib/python2.7/dist-packages/pydbus/registration.py", line 152, in register_object
    node_info = [Gio.DBusNodeInfo.new_for_xml(ni) for ni in node_info]
GLib.Error: g-markup-error-quark: 1:1: Error on line 1 char 1: Document must begin with an element (e.g. <book>) (2)

Contents of dbus_endpoints.py

from gi.repository import GLib
from pydbus import SessionBus

class DbusEndpoint:
    """
    <node>
        <interface name='org.matcher.keywords'>
            <method name='match_keywords'>
                <arg type='as' name='keywords' direction='in' />
                <arg type='s' name='data' direction='in' />
                <arg type='as' name='response' direction='out' />
            </method>
        </interface>
    </node>
    """

    def __init__(self, dbus_path):
        self.my_dbus_path = dbus_path

    def match_keywords(self, keywords, data):
        return [keyword for keyword in keywords if keyword in data]

if __name__ == '__main__':
    loop = GLib.MainLoop()
    bus = SessionBus()
    dbus_path = 'org.matcher.keywords'
    bus.publish(dbus_path, DbusEndpoint(dbus_path))
    loop.run()
psukys commented 6 years ago

Ah yes, I must agree with https://github.com/LEW21/pydbus/blob/6b0c847857a295da8903ee5f633c42e5c55a30d0/pydbus/publication.py#L9