dasbus-project / dasbus Goto Github PK
View Code? Open in Web Editor NEWDBus library in Python 3
Home Page: https://dasbus.readthedocs.io
License: GNU Lesser General Public License v2.1
DBus library in Python 3
Home Page: https://dasbus.readthedocs.io
License: GNU Lesser General Public License v2.1
I'm working on adding a dbus service for the the geopm project:
I would like to know the Unix user id of the process that originated request. The documentation on how to do this with the dbus module is here:
https://dbus.freedesktop.org/doc/dbus-python/tutorial.html#finding-out-the-caller-s-bus-name
There is an easy way to get the uid from a DBus interface once you know the unique name of the connecting bus. Is there an equivalent way to do this within an object published with dasbus?
Thanks,
Chris
I am working on a BLE application and to register gatt manager application using bluez i have to implement ObjectManager interface which is not possible with dasbus i guess. are you planning on supporting Object manager if not then do you have any suggestions on how to implement Objectmanager interface in order to work with BLE applications.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt
go to bottom of this page to see what i mean.
I've been flicking through the code and can't seem to find a way to remove a published object.
My setup is similar to example 5, How would I go about removing a room in this example and have it disappear from the bus?
Similarly to ORMs where one-to-one/one-to-many relations can be automatically dereferenced by the getter, dasbus could do same for values of OBJECT_PATH type. Something like
property_x = bus.get_proxy('org.MyService', '.../Controller').GetPathById('some_id').PropertyX
or
property_x = bus.get_proxy('org.MyService', '.../Controller').GetPathById('some_id').to_proxy().PropertyX
instead of:
path = bus.get_proxy('org.MyService', '.../Controller').GetPathById('some_id')
property_x = bus.get_proxy('org.MyService', path).PropertyX
That would significantly simplify the client's code as dereferencing work can easily be 25% of all dbus related code.
It would be good to regularly check whether the dasbus
library is compatible with the upstream pygobject
. See #51.
I'm implementing a MPRIS server on an existing app which already have an internal event loop.
Is there a way to use dasbus without the GLib event loop?
Hi,
I'm using ubuntu 20.04 on a Raspberry pi 3b+ (python version 3.8.2, dasbus 1.3) and I'm getting the following error:
Traceback (most recent call last):
File "/home/ubuntu/WiPiScanner/App/wpa_dbus.py", line 79, in
print(wpa_interface.SignalPoll())
File "/home/ubuntu/WiPiScanner/venv/lib/python3.8/site-packages/dasbus/client/handler.py", line 444, in _call_method
return self._get_method_reply(
File "/home/ubuntu/WiPiScanner/venv/lib/python3.8/site-packages/dasbus/client/handler.py", line 476, in _get_method_reply
return self._handle_method_error(error)
File "/home/ubuntu/WiPiScanner/venv/lib/python3.8/site-packages/dasbus/client/handler.py", line 487, in _handle_method_error
raise error
File "/home/ubuntu/WiPiScanner/venv/lib/python3.8/site-packages/dasbus/client/handler.py", line 474, in _get_method_reply
result = call(*args, **kwargs)
File "/home/ubuntu/WiPiScanner/venv/lib/python3.8/site-packages/dasbus/client/handler.py", line 57, in sync_call
return connection.call_sync(
gi.repository.GLib.Error: g-io-error-quark: Method “SignalPoll” returned type “(v)”, but expected “(a{sv})” (13)
and my code that is causing the issue:
`
for ap in AP_List:
interface = wpa_supp.GetInterface('wlan0')
wpa_interface = bus.get_proxy('fi.w1.wpa_supplicant1', interface)
network_props = { 'bssid' : Variant('s', ap.bssid),
'ssid' : Variant('s', ap.essid),
'psk': Variant('s', Inspect_Set.get(ssid=ap.essid).psk)}
network = wpa_interface.AddNetwork(network_props)
wpa_interface.SelectNetwork(network);
print('ssid:' + ap.essid + ' bssid:' + ap.bssid )
while (wpa_interface.State != 'disconnected') & (wpa_interface.State != 'completed'):
sleep(0.5)
if wpa_interface.State == 'completed':
print(wpa_interface.SignalPoll())
wpa_interface.RemoveNetwork(network)
`
I'm new to python and dbus, so I'm really not sure what to make of it, or how to get past it...
The documented example doesn't really explain or illustrate when callback
is called and what call
actually is.
See: https://dasbus.readthedocs.io/en/latest/examples.html
def callback(call):
print(call())
proxy.GetDevices(callback=callback)
loop.run()
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-dasbus-1.4-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-dasbus-1.4-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/python3 -Bm pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/tkloczko/rpmbuild/BUILD/dasbus-1.4
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, mock-3.5.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, flaky-3.7.0, cases-3.4.6, hypothesis-6.9.2
collected 169 items
tests/test_client.py ......... [ 5%]
tests/test_connection.py .............. [ 13%]
tests/test_container.py ........ [ 18%]
tests/test_dbus.py ............. [ 26%]
tests/test_error.py ......... [ 31%]
tests/test_identifier.py ....... [ 35%]
tests/test_interface.py ................. [ 45%]
tests/test_namespace.py ... [ 47%]
tests/test_observer.py .. [ 48%]
tests/test_property.py ......... [ 53%]
tests/test_proxy.py . [ 54%]
tests/test_server.py ..... [ 57%]
tests/test_signal.py ..... [ 60%]
tests/test_specification.py .......... [ 66%]
tests/test_structure.py ...................... [ 79%]
tests/test_typing.py ................. [ 89%]
tests/test_xml.py .................. [100%]
============================================================================= warnings summary =============================================================================
tests/test_connection.py:34
/home/tkloczko/rpmbuild/BUILD/dasbus-1.4/tests/test_connection.py:34: PytestCollectionWarning: cannot collect test class 'TestMessageBus' because it has a __init__ constructor (from: tests/test_connection.py)
class TestMessageBus(MessageBus):
-- Docs: https://docs.pytest.org/en/stable/warnings.html
===================================================================== 169 passed, 1 warning in 36.64s ======================================================================
Isolate the documentation for identifiers (https://github.com/rhinstaller/dasbus/blob/master/src/dasbus/identifier.py) and focus on using namespaces and functions from https://github.com/rhinstaller/dasbus/blob/master/src/dasbus/namespace.py. It is easier to grasp and good enough for smaller projects.
I'm having a look at the source code and dasbus/xml.py
caught my attention. xml.etree.ElementTree
and
xml.dom.minidom
are being imported and used without checking the validity of the xml
passed to them. Therefore, in case a malicious xml is passed to them it can cause problems such as crashing the server.
Also, I believe this will not have a security implication since if an attacker gains access to the server code they don't need this issue! And the code is not accessible from the client side either. Having said that, I wanted let you know about this issue and ask if you could possibly address it. Thanks.
Here's a quick example by changing a couple of lines in the hello world example in the project that would show the issue.
#
# Run the service org.example.HelloWorld.
#
from dasbus.loop import EventLoop
from dasbus.server.interface import dbus_interface
from dasbus.typing import Str
from common import HELLO_WORLD, SESSION_BUS
from dasbus.xml import XMLGenerator
# Amir added the following variable:
xml_str = '''<?xml version="1.0"?>
<!DOCTYPE bomb [
<!ENTITY a "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;">
]>
<bomb>&a;</bomb>
'''
@dbus_interface(HELLO_WORLD.interface_name)
class HelloWorld(object):
"""The DBus interface for HelloWorld."""
def Hello(self, name: Str) -> Str:
"""Generate a greeting.
:param name: someone to say hello
:return: a greeting
"""
return "Hello {}!".format(name)
if __name__ == "__main__":
# Print the generated XML specification.
# print(XMLGenerator.prettify_xml(HelloWorld.__dbus_xml__))
# Amir added the following line:
print(XMLGenerator.prettify_xml(xml_str))
try:
# Create an instance of the class HelloWorld.
hello_world = HelloWorld()
# Publish the instance at /org/example/HelloWorld.
SESSION_BUS.publish_object(HELLO_WORLD.object_path, hello_world)
# Register the service name org.example.HelloWorld.
SESSION_BUS.register_service(HELLO_WORLD.service_name)
# Start the event loop.
loop = EventLoop()
loop.run()
finally:
# Unregister the DBus service and objects.
SESSION_BUS.disconnect()
It would be great to get dasbus on Debian.
[0] https://wiki.debian.org/Packaging
[1] https://www.debian.org/doc/manuals/maint-guide/
In all examples involving “servers” there is a try ... finally
block:
try:
# some code
finally:
# Unregister the DBus service and objects.
SESSION_BUS.disconnect()
I would suggest to natively support the PEP 343 with
statement, in order to allow refactoring the above code as
with SESSION_BUS:
# some code
The implementation using with
-statement context managers should be straightforward.
I'm writing a little bluez app using dasbus. Reading values works great. Writing values half works: I get the write but the client never gets the GATT Write Response
. This leads to an error exactly like nettlep/gobbledegook#12
> ACL Data RX: Handle 64 flags 0x02 dlen 12 #146 [hci0] 20:53:37.594026
ATT: Write Request (0x12) len 7
Handle: 0x01f0
Data: 00014e2300
> HCI Event: Number of Completed Packets (0x13) plen 5 #147 [hci0] 20:53:37.594694
Num handles: 1
Handle: 64
Count: 2
< ACL Data TX: Handle 64 flags 0x00 dlen 9 #148 [hci0] 20:53:42.599869
ATT: Error Response (0x01) len 4
Write Request (0x12)
Handle: 0x01f0
Error: Unlikely Error (0x0e)
Code:
@dbus_interface("org.bluez.GattCharacteristic1")
class BLECharacteristicGatt(InterfaceTemplate):
def ReadValue(self, options: Dict[Str, Variant]) -> List[Byte]:
print(f"UUID {self.implementation._service._uuid} / {self.implementation._uuid} read value")
return list(self.implementation.value)
def WriteValue(self, value: List[Byte], options: Dict[Str, Variant]) -> None:
try:
print(f"UUID {self.implementation._service._uuid} / {self.implementation._uuid} write value")
self.implementation.value = value
except Exception as e:
print(e)
@property
def UUID(self) -> Str:
return self.implementation._uuid
@property
def Service(self) -> ObjPath:
return self.implementation._service._path
@property
def Flags(self) -> List[Str]:
return self.implementation._flags
Thoughts?
Hello,
in my DBus-API currently implemented with pydbus (and previously python-dbus) I am often returning multiple output values in signals and methods, e.g.
<node>
<interface name="de.test.my.Interface">
<method name="GetMultipleReturnValues">
<arg direction="out" type="s" name="out1"/>
<arg direction="out" type="s" name="out2"/>
</method>
</interface>
</node>
Is there a way to do this in dasbus?
Returning a Tuple like in
@dbus_signal("de.test.my.Interface")
class ControllerInterface(object):
def GetMultipleReturnValues(self) -> Tuple[Str, Str]:
return "foo", "bar"
would create a single out argument with the type (ss)
.
If I set __dbus_xml__
by hand:
class ControllerInterface:
__dbus_xml__ = """
<node>
<interface name="de.test.my.Interface">
<method name="GetMultipleReturnValues">
<arg direction="out" type="s" name="out1"/>
<arg direction="out" type="s" name="out2"/>
</method>
</interface>
</node>
"""
def GetMultipleReturnValues(self) -> Tuple[Str, Str]:
return "foo", "bar"
dasbus can't handle the output: TypeError: Tuple mismatches value's number of elements (ss) (('foo', 'bar'),)
Also if a class is decorated with @dbus_interface
, only methods which begin with an uppercase letter and only contain alphanumeric characters are added to the generated interface definition (this seems to be caused by https://github.com/rhinstaller/dasbus/blob/b04cdcdcdee9c1aaad6864f99ebf74e7a7933b3b/dasbus/server/interface.py#L264 ), which enforces more limits than the dbus specification for Member names
(wich would allow snake_case names), but does not check for the maximum allowed name length of 255 characters (a method with a name longer than 255 characters will show up in programs in the interface definition, but can't be called) - it would be helpful to mention this limitation in den Documentation, if this is intentional.
I am trying to use the Eval-GJS GNOME extension
To achieve its goal of creating an unrestricted Eval
method, it creates an interface in the org.gnome.Shell
service at /dev/ramottamado/EvalGjs
with a single method Eval
gdbus
can talk to that object :
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /dev/ramottamado/EvalGjs \
--method dev.ramottamado.EvalGjs.Eval "Main.overview.show();"
As can d-feet
But, dasbus
can't because it isn't in the DBus specification of the org.gnome.Shell
(it's a third-party thing) so it fails with dasbus
The following fails with
from dasbus.connection import SystemMessageBus, SessionMessageBus
from dasbus.loop import EventLoop
from dasbus.identifier import DBusServiceIdentifier, DBusObjectIdentifier
gjs_dbus = {
"gjs_namespace": ("org", "gnome", "Shell"),
"gjs": None,
"gjs_object": None
}
gjs_dbus["gjs"] = DBusServiceIdentifier(
namespace=gjs_dbus["gjs_namespace"], message_bus=SessionMessageBus())
gjs_dbus["gjs_object"] = DBusObjectIdentifier(
namespace=gjs_dbus["gjs_namespace"], basename="dev/ramottamado/EvalGjs")
gjs_proxy = gjs_dbus["gjs"].get_proxy(
gjs_dbus["gjs_object"], "dev.ramottamado.EvalGjs")
gjs_proxy.Eval()
Fails with
DBus specification has no member 'dev.ramottamado.EvalGjs.Eval'.
dasbus.specification.DBusSpecificationError: DBus specification has no member 'dev.ramottamado.EvalGjs.Eval'.
gjs_proxy
doesn't list the dev.ramottamado.EvalGjs
method when removing ifname
gjs_proxy = gjs_dbus["gjs"].get_proxy(
gjs_dbus["gjs_object"])
{'PropertiesChanged': 'org.freedesktop.DBus.Properties', 'Set': 'org.freedesktop.DBus.Properties', 'GetAll': 'org.freedesktop.DBus.Properties', 'Get': 'org.freedesktop.DBus.Properties', 'GetMachineId': 'org.freedesktop.DBus.Peer', 'Ping': 'org.freedesktop.DBus.Peer', 'Introspect': 'org.freedesktop.DBus.Introspectable'}
The dbus_interface
decorator doesn't generate XML specification for members of another DBus interface. It is not easy to discover why these members are not generated, because they are just silently skipped. Show a warning or some debug messages with information about a possible collision with another interface.
@dbus_interface("org.example.Project")
class InterfaceProject(InterfaceTemplate):
def Set(self, x: Int):
pass
In the example above, the Set
method will not be generated as a member of the org.example.Project
interface, because it is already defined in one of the standard interfaces, org.freedesktop.DBus.Properties
.
I'm sure I'm doing something wrong but I can't figure it out. Is there some way for me to override the "expected" return type that I'm overlooking?
I'm on Arch Linux with dasbus installed through pacman.
This is my script
from dasbus.connection import SessionMessageBus
from dasbus.unix import GLibClientUnix
bus = SessionMessageBus()
#dbus-send --print-reply --dest=org.kde.Solid.PowerManagement.PolicyAgent /org/kde/Solid/PowerManagement/PolicyAgent org.kde.Solid.PowerManagement.PolicyAgent.ListInhibitions
proxy = bus.get_proxy(
"org.kde.Solid.PowerManagement.PolicyAgent",
"/org/kde/Solid/PowerManagement/PolicyAgent")
print(proxy.ListInhibitions())
I'm expecting to get a printout something like what dbus-send returns (my KDE dbus command is in the python file)
method return time=1714249844.635597 sender=:1.24 -> destination=:1.202 serial=1028 reply_serial=2
array [
struct {
string "Steam"
string "Client interface"
}
]
Instead I'm getting this error:
Traceback (most recent call last):
File "./main.py", line 12, in <module>
print(proxy.ListInhibitions())
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/dasbus/client/handler.py", line 450, in _call_method
return self._get_method_reply(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/dasbus/client/handler.py", line 483, in _get_method_reply
return self._handle_method_error(error)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/dasbus/client/handler.py", line 518, in _handle_method_error
raise error
File "/usr/lib/python3.12/site-packages/dasbus/client/handler.py", line 480, in _get_method_reply
result = call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/dasbus/client/handler.py", line 57, in sync_call
return connection.call_sync(
^^^^^^^^^^^^^^^^^^^^^
gi.repository.GLib.GError: g-io-error-quark: Method “ListInhibitions” returned type “(a(ss))”, but expected “(a{ss})” (13)
Ubuntu 20.04
dasbus: 1.6
Python: 3.8
I'm having trouble with signals being received, so I tried the examples/02_notification
, running listener.py
in one terminal and client.py
in another.
The notification from the client sends; I can see it in dbus-monitor
. The listener never prints from the callback.
Is the example out of date? If not, any pointers to getting it to work?
Thanks!
Consider the following script
one.py.txt
If this script is run, and the following loop is run in another (bash) window
while busctl --user call com.carnegierobotics.test /com/carnegierobotics/test com.carnegierobotics.dasbus.test One; do echo "DONE"; done
resident memory seems to grow indefinitely. Not sure if this is a dasbus bug or a glib bug.
I'm looking into adding support for the "new" dbus API in PyBluez. In order to initiate a incoming connection with BlueZ's Profile interface, BlueZ accepts the connection and passes the socket as a file descriptor with the NewConnection
call. However this is not currently supported in dasbus.
Are there any plans to support file descriptor passing?
Looks like something is wrong and pytest fails in two units with pytest 8.2.1
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-dasbus-1.7-7.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-dasbus-1.7-7.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase(PosixPath('/home/tkloczko/rpmbuild/BUILD/dasbus-1.7/.hypothesis/examples'))
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/tkloczko/rpmbuild/BUILD/dasbus-1.7
configfile: pyproject.toml
testpaths: tests
plugins: hypothesis-6.100.0, benchmark-4.0.0, mock-3.14.0, timeout-2.3.1, twisted-1.14.1, tornasync-0.6.0.post2, trio-0.8.0, anyio-4.3.0, asyncio-0.23.7
asyncio: mode=strict
collected 232 items / 5 errors
========================================================================================== ERRORS ===========================================================================================
____________________________________________________________________________ ERROR collecting tests/lib_dbus.py _____________________________________________________________________________
/usr/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
result: Optional[TResult] = func()
/usr/lib/python3.10/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
/usr/lib/python3.10/site-packages/_pytest/unittest.py:90: in collect
self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.10/site-packages/_pytest/unittest.py:75: in newinstance
return self.obj("runTest")
E TypeError: Can't instantiate abstract class AbstractDBusTestCase with abstract methods _get_message_bus, _get_service
____________________________________________________________________________ ERROR collecting tests/lib_dbus.py _____________________________________________________________________________
/usr/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
result: Optional[TResult] = func()
/usr/lib/python3.10/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
/usr/lib/python3.10/site-packages/_pytest/unittest.py:90: in collect
self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.10/site-packages/_pytest/unittest.py:75: in newinstance
return self.obj("runTest")
E TypeError: Can't instantiate abstract class DBusThreadedTestCase with abstract methods _get_message_bus, _get_service
____________________________________________________________________________ ERROR collecting tests/lib_dbus.py _____________________________________________________________________________
/usr/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
result: Optional[TResult] = func()
/usr/lib/python3.10/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
/usr/lib/python3.10/site-packages/_pytest/unittest.py:90: in collect
self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.10/site-packages/_pytest/unittest.py:75: in newinstance
return self.obj("runTest")
E TypeError: Can't instantiate abstract class DBusSpawnedTestCase with abstract methods _get_message_bus, _get_service
____________________________________________________________________________ ERROR collecting tests/test_dbus.py ____________________________________________________________________________
/usr/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
result: Optional[TResult] = func()
/usr/lib/python3.10/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
/usr/lib/python3.10/site-packages/_pytest/unittest.py:90: in collect
self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.10/site-packages/_pytest/unittest.py:75: in newinstance
return self.obj("runTest")
E TypeError: Can't instantiate abstract class DBusThreadedTestCase with abstract methods _get_message_bus, _get_service
____________________________________________________________________________ ERROR collecting tests/test_unix.py ____________________________________________________________________________
/usr/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
result: Optional[TResult] = func()
/usr/lib/python3.10/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
/usr/lib/python3.10/site-packages/_pytest/unittest.py:90: in collect
self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
/usr/lib/python3.10/site-packages/_pytest/unittest.py:75: in newinstance
return self.obj("runTest")
E TypeError: Can't instantiate abstract class DBusSpawnedTestCase with abstract methods _get_message_bus, _get_service
================================================================================== short test summary info ==================================================================================
ERROR tests/lib_dbus.py::AbstractDBusTestCase - TypeError: Can't instantiate abstract class AbstractDBusTestCase with abstract methods _get_message_bus, _get_service
ERROR tests/lib_dbus.py::DBusThreadedTestCase - TypeError: Can't instantiate abstract class DBusThreadedTestCase with abstract methods _get_message_bus, _get_service
ERROR tests/lib_dbus.py::DBusSpawnedTestCase - TypeError: Can't instantiate abstract class DBusSpawnedTestCase with abstract methods _get_message_bus, _get_service
ERROR tests/test_dbus.py::DBusThreadedTestCase - TypeError: Can't instantiate abstract class DBusThreadedTestCase with abstract methods _get_message_bus, _get_service
ERROR tests/test_unix.py::DBusSpawnedTestCase - TypeError: Can't instantiate abstract class DBusSpawnedTestCase with abstract methods _get_message_bus, _get_service
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================================== 5 errors in 0.53s =====================================================================================
I am trying to make a sync_call with two inputs.
The command with dbus-send is this:
dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.DBus.Properties.Get string:org.freedesktop.NetworkManager string:ActiveConnections
But I can't get it to work with dasbus. This is the script I wrote:
from dasbus.connection import SystemMessageBus
from gi.repository import GLib
bus = SystemMessageBus()
result = GLibClient.sync_call(
connection=bus.connection,
service_name="org.freedesktop.NetworkManager",
object_path="/org/freedesktop/NetworkManager",
interface_name="org.freedesktop.DBus.Properties",
method_name="org.freedesktop.DBus.Properties.Get",
parameters=GLib.Variant("as", ["org.freedesktop.NetworkManager", "ActiveConnections"]),
reply_type=GLib.VariantType('as'),
)
print("Result:", result)
I get this error:
(process:549589): GLib-GIO-CRITICAL **: 00:42:27.528: g_dbus_connection_call_sync_internal: assertion 'method_name != NULL && g_dbus_is_member_name (method_name)' failed
Result: None
Could you help me out run this script?
Clients should be able to emit signals on D-Bus interfaces. See Gio.DBusConnection.emit_signal. Create an example for this use case and mention https://github.com/containers/bluechi/tree/main/tests/tools/FFI for a possible inspiration.
Sometimes the DBus API requires to connect to signals of DBus objects that don't exist yet:
https://flatpak.github.io/xdg-desktop-portal/#common-conventions
That is not possible to do with proxy objects and it is necessary to use a layer with a lower level of abstraction:
from dasbus.client.handler import GLibClient
GLibClient.subscribe_signal(
bus.connection,
service_name,
object_path,
interface_name,
signal_name,
callback,
)
Let's figure out how to make these layers easier to use and discover.
From https://docs.python.org/3.9/whatsnew/3.9.html#pep-585-builtin-generic-types:
In type annotations you can now use built-in collection types such as list and dict as generic types instead of importing the corresponding capitalized types (e.g. List or Dict) from typing.
These type hints should be supported by dasbus since Python 3.9.
I just converted a process from pydbus to dasbus. Everything works fine except that I get an exception (below) when I stop the process. There seems to be an atexit
hook that gets executed, but I have no idea why it's failing. I must not have initialized something, but I have no idea what it is. Please advise.
(process:7971): GLib-GIO-CRITICAL **: 11:18:03.611: g_dbus_connection_call_sync_internal: assertion 'bus_name == NULL || g_dbus_is_name (bus_name)' failed
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/dasbus/client/handler.py", line 477, in _get_method_reply
return self._handle_method_error(error)
File "/usr/lib/python3.9/site-packages/dasbus/client/handler.py", line 486, in _handle_method_error
raise error
File "/usr/lib/python3.9/site-packages/dasbus/client/handler.py", line 475, in _get_method_reply
return self._handle_method_result(result)
File "/usr/lib/python3.9/site-packages/dasbus/client/handler.py", line 505, in _handle_method_result
values = unwrap_variant(result)
File "/usr/lib/python3.9/site-packages/dasbus/typing.py", line 177, in unwrap_variant
type_string = variant.get_type_string()
AttributeError: 'NoneType' object has no attribute 'get_type_string'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.