UDisks2 Python Automounting

Yet another full evening spent reading forums and mailing lists trying to hack together a few lines of code. Thanks, DBus. The following Python snippet auto mounts USB drives (I needed on an appliance with no any running evoluted desktop environment doing it). import dbus from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) bus = dbus.SystemBus() def callback_function(path, interfaces): try: obj = bus.get_object('org.freedesktop.UDisks2', path) iface = dbus.Interface(obj, 'org.freedesktop.UDisks2.Filesystem') path = iface.get_dbus_method('Mount', dbus_interface='org.…

Keep reading

ReloadOrRestartUnit

Given that I just spent two hours to write three lines of code, I share here my initial problem and the final solution for those looking for the same thing in the future (including myself). The problem is: in a graphical Python application running as a normal user, obtain authorization to restart a system service. The quick and dirty solution involves the execution of a command starting with gksu, but this method has been discouraged in favor of PolicyKit. So I started looking for PolicyKit documentation. Which lacks any viable…

Keep reading