Unmount a drive with python with udisks2 via dbus

81 views Asked by At

I'm trying to achieve the title.

Here is my code:

from dbus_next.aio import MessageBus

async def unmount_device(device_path):
    bus = await MessageBus().connect()
    udisk_obj = bus.get_proxy_object('org.freedesktop.UDisks2', device_path)
    udisk_interface = udisk_obj.get_interface('org.freedesktop.UDisks2.Filesystem')

    udisk_interface.Unmount()

dbus-python is unavailable on Debian Bullseye, so I chosed dbus-next.

But it's also hard and painful to use.

What the hexk I should do to hack myself into udisk and hack it to umount my chosen drive?

This code drops me an error:

dbus_next.errors.InvalidAddressError: DBUS_SESSION_BUS_ADDRESS not set and could not get DISPLAY environment variable to get bus address

But this is a headless system and I'm reaching it over SSH (but later I wish to use this script via systemd.

Thank you if you could guide me a bit.

1

There are 1 answers

0
user1686 On

You are trying to connect to the wrong bus. UDisks2 is available on the system bus:

bus = await MessageBus(bus_type=BusType.SYSTEM).connect()