dbus api uses a special format to describe complex parameters.
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.
In my example I want to call the Mount() method of the Filesystem object. This method got the signature a{sv}.
Mount() is defined like this
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
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
We learn from it that a{sv} is an ARRAY that contains one (or multiple?) DICT (list of key-value pairs). The key is STRING, the value is VARIANT which is data of any type preceded by a type code.
Thankfully we don't have to deal with low-level details. Python is going to deal with that.
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
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
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
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
So the final solution looks like
obj.Mount(dict(fstype="vfat", options="ro"), 
dbus_interface="org.freedesktop.UDisks2.Filesystem")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With