diff --git a/src/calibre/devices/udisks.py b/src/calibre/devices/udisks.py index ba26c2b56c..d79b626f36 100644 --- a/src/calibre/devices/udisks.py +++ b/src/calibre/devices/udisks.py @@ -5,8 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import dbus -import os +import dbus, os def node_mountpoint(node): @@ -56,15 +55,6 @@ class UDisks(object): parent = device_node_path while parent[-1] in '0123456789': parent = parent[:-1] - devices = [str(x) for x in self.main.EnumerateDeviceFiles()] - for d in devices: - if d.startswith(parent) and d != parent: - try: - self.unmount(d) - except: - import traceback - print 'Failed to unmount:', d - traceback.print_exc() d = self.device(parent) d.DriveEject([]) @@ -76,13 +66,19 @@ def eject(node_path): u = UDisks() u.eject(node_path) +def umount(node_path): + u = UDisks() + u.unmount(node_path) + if __name__ == '__main__': import sys dev = sys.argv[1] print 'Testing with node', dev u = UDisks() print 'Mounted at:', u.mount(dev) - print 'Ejecting' + print 'Unmounting' + u.unmount(dev) + print 'Ejecting:' u.eject(dev) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index aa4f0d06f4..94744c521f 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -733,24 +733,31 @@ class Device(DeviceConfig, DevicePlugin): pass def eject_linux(self): - try: - from calibre.devices.udisks import eject - return eject(self._linux_main_device_node) - except: - pass - drives = self.find_device_nodes() + from calibre.devices.udisks import eject, umount + drives = [d for d in self.find_device_nodes() if d] + for d in drives: + try: + umount(d) + except: + pass + for d in drives: + try: + eject(d) + except Exception, e: + print 'Udisks eject call for:', d, 'failed:' + print '\t', str(e) + for drive in drives: - if drive: - cmd = 'calibre-mount-helper' - if getattr(sys, 'frozen_path', False): - cmd = os.path.join(sys.frozen_path, cmd) - cmd = [cmd, 'eject'] - mp = getattr(self, "_linux_mount_map", {}).get(drive, - 'dummy/')[:-1] - try: - subprocess.Popen(cmd + [drive, mp]).wait() - except: - pass + cmd = 'calibre-mount-helper' + if getattr(sys, 'frozen_path', False): + cmd = os.path.join(sys.frozen_path, cmd) + cmd = [cmd, 'eject'] + mp = getattr(self, "_linux_mount_map", {}).get(drive, + 'dummy/')[:-1] + try: + subprocess.Popen(cmd + [drive, mp]).wait() + except: + pass def eject(self): if islinux: