[英]how to pass 'a{sv}' dbus signature to udisks2.Mount() from python?
dbus
api uses a special format to describe complex parameters. dbus
api 使用一种特殊的格式来描述复杂的参数。
Since dbus specification wasn't written with Python in mind, it's a far fetch to find out what parameter structure you exactly have to pass.由于编写 dbus 规范时没有考虑到 Python,因此要找出您确切必须传递的参数结构是一项艰巨的任务。
In my example I want to call the Mount()
method of the Filesystem
object.在我的示例中,我想调用Filesystem
object 的Mount()
方法。 This method got the signature a{sv}
.这个方法得到了签名a{sv}
。
Mount()
is defined like this Mount()
是这样定义的
org.freedesktop.UDisks2.Filesystem
...
The Mount() method
Mount (IN a{sv} options,
OUT s mount_path);
source: http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Mount来源: http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Mount
The complete code to mount a partition is this:挂载分区的完整代码如下:
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")
Where... is the parameters in question.其中...是有问题的参数。
The answer is separated into different layers:答案分为不同的层:
The parameter structure for dbus is defined here: https://dbus.freedesktop.org/doc/dbus-specification.html#type-system dbus 的参数结构在这里定义: https://dbus.freedesktop.org/doc/dbus-specification.html#type-system
We learn from it that a{sv}
is an ARRAY that contains one (or multiple?) DICT (list of key-value pairs).我们从中了解到a{sv}
是一个包含一个(或多个?)DICT(键值对列表)的数组。 The key is STRING, the value is VARIANT which is data of any type preceded by a type code.键是 STRING,值是 VARIANT,它是前面带有类型代码的任何类型的数据。
Thankfully we don't have to deal with low-level details.值得庆幸的是,我们不必处理低级细节。 Python is going to deal with that. Python 将处理这个问题。
So the solution simply is:所以解决方案很简单:
obj.Mount(dict(key="value", key2="value2"),
dbus_interface="org.freedesktop.UDisks2.Filesystem")
The actual key names are defined in udisks docs实际的键名在 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.
from http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Mount来自http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Mount
while standard options refers to而标准选项是指
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.
from http://storaged.org/doc/udisks2-api/latest/udisks-std-options.html来自http://storaged.org/doc/udisks2-api/latest/udisks-std-options.html
So, adding the key names we have因此,添加我们拥有的键名
obj.Mount(dict(fstype="value", options="value2"),
dbus_interface="org.freedesktop.UDisks2.Filesystem")
Regarding the values I think you have to study the sections Filesystem Independent Mount Options
and Filesystem Dependent Mount Options
from https://linux.die.net/man/8/mount关于值,我认为您必须研究https://linux.die.net/man/8/mount中的Filesystem Independent Mount Options
和Filesystem Dependent Mount Options
部分
So the final solution looks like所以最终的解决方案看起来像
obj.Mount(dict(fstype="vfat", options="ro"),
dbus_interface="org.freedesktop.UDisks2.Filesystem")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.