dbus接口使用特殊的格式来描述复杂的参数。
由于dbus规范在编写时并没有考虑到Python,因此要找出确切必须传递的参数结构是很难的。
在我的示例中,我想调用Filesystem对象的Mount()方法。此方法获得了签名a{sv}。
Mount()的定义如下
org.freedesktop.UDisks2.Filesystem
...
The Mount() method
Mount (IN a{sv} options,
OUT s mount_path);来源:http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Mount
挂载分区的完整代码如下:
bus = dbus.SystemBus()
device = "/org/freedesktop/UDisks2/block_devices/sdi1"
obj = bus.get_object('org.freedesktop.UDisks2', device)
obj.Mount(..., dbus_interface="org.freedesktop.UDisks2.Filesystem")哪里..。是有问题的参数。
发布于 2021-04-05 18:10:40
答案被分成不同的层次:
dbus的参数结构的定义如下:https://dbus.freedesktop.org/doc/dbus-specification.html#type-system
我们从中了解到,a{sv}是一个包含一个(或多个?)DICT (键值对列表)。关键字是字符串,值是VARIANT,它是前面有类型代码的任何类型的数据。
谢天谢地,我们不必处理低级细节。Python将会处理这个问题。
所以解决方案很简单:
obj.Mount(dict(key="value", key2="value2"),
dbus_interface="org.freedesktop.UDisks2.Filesystem")实际的密钥名称在udisks文档中定义
IN a{sv} options: Options - known options (in addition to standard options)
includes fstype (of type 's') and options (of type 's').
OUT s mount_path: The filesystem path where the device was mounted.来自http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Mount
而标准选项指的是
Option name, Value type, Description
auth.no_user_interaction, 'b', If set to TRUE, then no user interaction will happen when checking if the method call is authorized.来自http://storaged.org/doc/udisks2-api/latest/udisks-std-options.html
因此,添加我们已有的关键字名称
obj.Mount(dict(fstype="value", options="value2"),
dbus_interface="org.freedesktop.UDisks2.Filesystem")关于值,我认为您必须研究https://linux.die.net/man/8/mount中的Filesystem Independent Mount Options和Filesystem Dependent Mount Options部分
所以最终的解决方案看起来像这样
obj.Mount(dict(fstype="vfat", options="ro"),
dbus_interface="org.freedesktop.UDisks2.Filesystem")https://stackoverflow.com/questions/66940848
复制相似问题