mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Linux device drivers: Fix udisks based ejecting for devices with multiple nodes
This commit is contained in:
parent
2bd9f63f29
commit
8b0b1312e3
@ -5,8 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import dbus
|
import dbus, os
|
||||||
import os
|
|
||||||
|
|
||||||
def node_mountpoint(node):
|
def node_mountpoint(node):
|
||||||
|
|
||||||
@ -56,15 +55,6 @@ class UDisks(object):
|
|||||||
parent = device_node_path
|
parent = device_node_path
|
||||||
while parent[-1] in '0123456789':
|
while parent[-1] in '0123456789':
|
||||||
parent = parent[:-1]
|
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 = self.device(parent)
|
||||||
d.DriveEject([])
|
d.DriveEject([])
|
||||||
|
|
||||||
@ -76,13 +66,19 @@ def eject(node_path):
|
|||||||
u = UDisks()
|
u = UDisks()
|
||||||
u.eject(node_path)
|
u.eject(node_path)
|
||||||
|
|
||||||
|
def umount(node_path):
|
||||||
|
u = UDisks()
|
||||||
|
u.unmount(node_path)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
dev = sys.argv[1]
|
dev = sys.argv[1]
|
||||||
print 'Testing with node', dev
|
print 'Testing with node', dev
|
||||||
u = UDisks()
|
u = UDisks()
|
||||||
print 'Mounted at:', u.mount(dev)
|
print 'Mounted at:', u.mount(dev)
|
||||||
print 'Ejecting'
|
print 'Unmounting'
|
||||||
|
u.unmount(dev)
|
||||||
|
print 'Ejecting:'
|
||||||
u.eject(dev)
|
u.eject(dev)
|
||||||
|
|
||||||
|
|
||||||
|
@ -733,14 +733,21 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def eject_linux(self):
|
def eject_linux(self):
|
||||||
|
from calibre.devices.udisks import eject, umount
|
||||||
|
drives = [d for d in self.find_device_nodes() if d]
|
||||||
|
for d in drives:
|
||||||
try:
|
try:
|
||||||
from calibre.devices.udisks import eject
|
umount(d)
|
||||||
return eject(self._linux_main_device_node)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
drives = self.find_device_nodes()
|
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:
|
for drive in drives:
|
||||||
if drive:
|
|
||||||
cmd = 'calibre-mount-helper'
|
cmd = 'calibre-mount-helper'
|
||||||
if getattr(sys, 'frozen_path', False):
|
if getattr(sys, 'frozen_path', False):
|
||||||
cmd = os.path.join(sys.frozen_path, cmd)
|
cmd = os.path.join(sys.frozen_path, cmd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user