From 12871ae8ceb1575787125e5408959bb57761c461 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Dec 2009 19:08:16 -0700 Subject: [PATCH] Better error recovery and error message when trying to find mount points on OS X fails --- setup/installer/linux/freeze.py | 2 +- src/calibre/debug.py | 77 ++--------------------------- src/calibre/devices/__init__.py | 2 + src/calibre/devices/usbms/device.py | 18 ++++++- 4 files changed, 23 insertions(+), 76 deletions(-) diff --git a/setup/installer/linux/freeze.py b/setup/installer/linux/freeze.py index 53d8bde506..f5188bbbd0 100644 --- a/setup/installer/linux/freeze.py +++ b/setup/installer/linux/freeze.py @@ -23,7 +23,7 @@ class LinuxFreeze(Command): is64bit = platform.architecture()[0] == '64bit' 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' if is64bit else '4.4.1') diff --git a/src/calibre/debug.py b/src/calibre/debug.py index bb958996b6..6ad49dfe65 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -6,9 +6,9 @@ __copyright__ = '2008, Kovid Goyal ' Embedded console for debugging. ''' -import sys, os, pprint +import sys, os from calibre.utils.config import OptionParser -from calibre.constants import iswindows, isosx +from calibre.constants import iswindows from calibre import prints def option_parser(): @@ -61,77 +61,8 @@ def migrate(old, new): print 'Database migrated to', os.path.abspath(new) def debug_device_driver(): - from calibre.customize.ui import device_plugins - from calibre.devices.scanner import DeviceScanner - 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" - + from calibre.devices import debug + print debug() if iswindows: raw_input('Press Enter to continue...') diff --git a/src/calibre/devices/__init__.py b/src/calibre/devices/__init__.py index c971c9d79d..95e33cbd24 100644 --- a/src/calibre/devices/__init__.py +++ b/src/calibre/devices/__init__.py @@ -76,7 +76,9 @@ def debug(): ioreg = None if isosx: from calibre.devices.usbms.device import Device + mount = repr(Device.osx_run_mount()) ioreg = Device.run_ioreg() + ioreg = 'Output from mount:\n\n'+mount+'\n\n'+ioreg connected_devices = [] for dev in device_plugins(): out('Looking for', dev.__class__.__name__) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index fcefdb7582..d026904a35 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -380,14 +380,28 @@ class Device(DeviceConfig, DevicePlugin): break 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): - mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read() + mount = self.osx_run_mount() names = self.get_osx_mountpoints() dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+' if 'main' not in names.keys(): raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__) 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_b_pat = names['cardb'] if 'cardb' in names.keys() else None