From 8156e13e837cf837161ab1209b8bf2f5e6cd3057 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 23 Jun 2012 11:01:21 +0530 Subject: [PATCH] Finish up the UDisks2 support, however for the moment we continue to use UDisks1 as who knows what state UDisks2 is in all the distros out there --- src/calibre/devices/udisks.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/udisks.py b/src/calibre/devices/udisks.py index 54a21cacff..112cd3d87f 100644 --- a/src/calibre/devices/udisks.py +++ b/src/calibre/devices/udisks.py @@ -5,10 +5,6 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -# First repeat after me: Linux desktop infrastructure is designed by a -# committee of rabid monkeys on crack. They would not know a decent desktop if -# it was driving the rabid monkey extermination truck that runs them over. - import os, dbus, re def node_mountpoint(node): @@ -67,6 +63,7 @@ class UDisks2(object): BLOCK = 'org.freedesktop.UDisks2.Block' FILESYSTEM = 'org.freedesktop.UDisks2.Filesystem' + DRIVE = 'org.freedesktop.UDisks2.Drive' def __init__(self): self.bus = dbus.SystemBus() @@ -131,6 +128,21 @@ class UDisks2(object): raise return mp + def unmount(self, device_node_path): + d = self.device(device_node_path) + d.Unmount({'force':True, 'auth.no_user_interaction':True}, + dbus_interface=self.FILESYSTEM) + + def drive_for_device(self, device): + drive = device.Get(self.BLOCK, 'Drive', + dbus_interface='org.freedesktop.DBus.Properties') + return self.bus.get_object('org.freedesktop.UDisks2', drive) + + def eject(self, device_node_path): + drive = self.drive_for_device(self.device(device_node_path)) + drive.Eject({'auth.no_user_interaction':True}, + dbus_interface=self.DRIVE) + def get_udisks(ver=None): if ver is None: try: @@ -140,7 +152,6 @@ def get_udisks(ver=None): return u return UDisks2() if ver == 2 else UDisks() - def mount(node_path): u = UDisks() u.mount(node_path)