mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Better error recovery and error message when trying to find mount points on OS X fails
This commit is contained in:
parent
ef4f68c6b6
commit
12871ae8ce
@ -23,7 +23,7 @@ class LinuxFreeze(Command):
|
|||||||
|
|
||||||
is64bit = platform.architecture()[0] == '64bit'
|
is64bit = platform.architecture()[0] == '64bit'
|
||||||
arch = 'x86_64' if is64bit else 'i686'
|
arch = 'x86_64' if is64bit else 'i686'
|
||||||
ffi = '/usr/lib/libffi.so.5' if is64bit else '/usr/lib/gcc/i686-pc-linux-gnu/4.4.1/libffi.so.4'
|
ffi = '/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.2/libffi.so.4' if is64bit else '/usr/lib/gcc/i686-pc-linux-gnu/4.4.1/libffi.so.4'
|
||||||
stdcpp = '/usr/lib/gcc/%s-pc-linux-gnu/%s/libstdc++.so.6'%(arch, '4.4.2'
|
stdcpp = '/usr/lib/gcc/%s-pc-linux-gnu/%s/libstdc++.so.6'%(arch, '4.4.2'
|
||||||
if is64bit else '4.4.1')
|
if is64bit else '4.4.1')
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
Embedded console for debugging.
|
Embedded console for debugging.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys, os, pprint
|
import sys, os
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
from calibre.constants import iswindows, isosx
|
from calibre.constants import iswindows
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
@ -61,77 +61,8 @@ def migrate(old, new):
|
|||||||
print 'Database migrated to', os.path.abspath(new)
|
print 'Database migrated to', os.path.abspath(new)
|
||||||
|
|
||||||
def debug_device_driver():
|
def debug_device_driver():
|
||||||
from calibre.customize.ui import device_plugins
|
from calibre.devices import debug
|
||||||
from calibre.devices.scanner import DeviceScanner
|
print debug()
|
||||||
s = DeviceScanner()
|
|
||||||
s.scan()
|
|
||||||
devices = s.devices
|
|
||||||
if not iswindows:
|
|
||||||
devices = [list(x) for x in devices]
|
|
||||||
for d in devices:
|
|
||||||
for i in range(3):
|
|
||||||
d[i] = hex(d[i])
|
|
||||||
|
|
||||||
print 'USB devices on system:\n', pprint.pprint(devices)
|
|
||||||
if iswindows:
|
|
||||||
wmi = __import__('wmi', globals(), locals(), [], -1)
|
|
||||||
drives = []
|
|
||||||
print 'Drives detected:'
|
|
||||||
print '\t', '(ID, Partitions, Drive letter)'
|
|
||||||
for drive in wmi.WMI(find_classes=False).Win32_DiskDrive():
|
|
||||||
if drive.Partitions == 0:
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
partition = drive.associators("Win32_DiskDriveToDiskPartition")[0]
|
|
||||||
logical_disk = partition.associators('Win32_LogicalDiskToPartition')[0]
|
|
||||||
prefix = logical_disk.DeviceID+os.sep
|
|
||||||
drives.append((str(drive.PNPDeviceID), drive.Index, prefix))
|
|
||||||
except IndexError:
|
|
||||||
drives.append((str(drive.PNPDeviceID), 'No mount points found'))
|
|
||||||
for drive in drives:
|
|
||||||
print '\t', drive
|
|
||||||
if isosx:
|
|
||||||
from calibre.devices.usbms.device import Device
|
|
||||||
raw = Device.run_ioreg()
|
|
||||||
open('/tmp/ioreg.txt', 'wb').write(raw)
|
|
||||||
print 'ioreg output saved to /tmp/ioreg.txt'
|
|
||||||
connected_devices = []
|
|
||||||
for dev in device_plugins():
|
|
||||||
print 'Looking for', dev.__class__.__name__
|
|
||||||
connected = s.is_device_connected(dev, debug=True)
|
|
||||||
if connected:
|
|
||||||
connected_devices.append(dev)
|
|
||||||
|
|
||||||
errors = {}
|
|
||||||
success = False
|
|
||||||
for dev in connected_devices:
|
|
||||||
print 'Device possibly connected:', dev.__class__.name
|
|
||||||
print 'Trying to open device...',
|
|
||||||
try:
|
|
||||||
dev.open()
|
|
||||||
print 'OK'
|
|
||||||
except:
|
|
||||||
import traceback
|
|
||||||
errors[dev] = traceback.format_exc()
|
|
||||||
print 'failed'
|
|
||||||
continue
|
|
||||||
success = True
|
|
||||||
if hasattr(dev, '_main_prefix'):
|
|
||||||
print 'Main memory:', repr(dev._main_prefix)
|
|
||||||
print 'Total space:', dev.total_space()
|
|
||||||
break
|
|
||||||
if not success and errors:
|
|
||||||
print 'Opening of the following devices failed'
|
|
||||||
for dev,msg in errors.items():
|
|
||||||
print dev
|
|
||||||
print msg
|
|
||||||
print
|
|
||||||
if isosx and os.path.exists('/tmp/ioreg.txt'):
|
|
||||||
print
|
|
||||||
print
|
|
||||||
print "Don't forget to send the file /tmp/ioreg.txt as well"
|
|
||||||
print "You can view it by typing the command: open /tmp/ioreg.txt"
|
|
||||||
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
raw_input('Press Enter to continue...')
|
raw_input('Press Enter to continue...')
|
||||||
|
|
||||||
|
@ -76,7 +76,9 @@ def debug():
|
|||||||
ioreg = None
|
ioreg = None
|
||||||
if isosx:
|
if isosx:
|
||||||
from calibre.devices.usbms.device import Device
|
from calibre.devices.usbms.device import Device
|
||||||
|
mount = repr(Device.osx_run_mount())
|
||||||
ioreg = Device.run_ioreg()
|
ioreg = Device.run_ioreg()
|
||||||
|
ioreg = 'Output from mount:\n\n'+mount+'\n\n'+ioreg
|
||||||
connected_devices = []
|
connected_devices = []
|
||||||
for dev in device_plugins():
|
for dev in device_plugins():
|
||||||
out('Looking for', dev.__class__.__name__)
|
out('Looking for', dev.__class__.__name__)
|
||||||
|
@ -380,14 +380,28 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
break
|
break
|
||||||
return self.osx_sort_names(names)
|
return self.osx_sort_names(names)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def osx_run_mount(cls):
|
||||||
|
for i in range(3):
|
||||||
|
try:
|
||||||
|
return subprocess.Popen('mount',
|
||||||
|
stdout=subprocess.PIPE).communicate()[0]
|
||||||
|
except IOError: # Probably an interrupted system call
|
||||||
|
if i == 2:
|
||||||
|
raise
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
def open_osx(self):
|
def open_osx(self):
|
||||||
mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read()
|
mount = self.osx_run_mount()
|
||||||
names = self.get_osx_mountpoints()
|
names = self.get_osx_mountpoints()
|
||||||
dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+'
|
dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+'
|
||||||
if 'main' not in names.keys():
|
if 'main' not in names.keys():
|
||||||
raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__)
|
raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__)
|
||||||
main_pat = dev_pat % names['main']
|
main_pat = dev_pat % names['main']
|
||||||
self._main_prefix = re.search(main_pat, mount).group(2) + os.sep
|
main_match = re.search(main_pat, mount)
|
||||||
|
if main_match is None:
|
||||||
|
raise DeviceError(_('Unable to detect the %s mount point. Try rebooting.')%self.__class__.__name__)
|
||||||
|
self._main_prefix = main_match.group(2) + os.sep
|
||||||
card_a_pat = names['carda'] if 'carda' in names.keys() else None
|
card_a_pat = names['carda'] if 'carda' in names.keys() else None
|
||||||
card_b_pat = names['cardb'] if 'cardb' in names.keys() else None
|
card_b_pat = names['cardb'] if 'cardb' in names.keys() else None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user