diff --git a/src/calibre/debug.py b/src/calibre/debug.py index 6ad49dfe65..63e11ae368 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -62,7 +62,7 @@ def migrate(old, new): def debug_device_driver(): from calibre.devices import debug - print debug() + debug(ioreg_to_tmp=True, buf=sys.stdout) if iswindows: raw_input('Press Enter to continue...') diff --git a/src/calibre/devices/__init__.py b/src/calibre/devices/__init__.py index 95e33cbd24..3fead7b75f 100644 --- a/src/calibre/devices/__init__.py +++ b/src/calibre/devices/__init__.py @@ -27,14 +27,15 @@ def strftime(epoch, zone=time.gmtime): src[2] = INVERSE_MONTH_MAP[int(src[2])] return ' '.join(src) -def debug(): +def debug(ioreg_to_tmp=False, buf=None): from calibre.customize.ui import device_plugins from calibre.devices.scanner import DeviceScanner from calibre.constants import iswindows, isosx, __version__ from calibre import prints oldo, olde = sys.stdout, sys.stderr - buf = StringIO() + if buf is None: + buf = StringIO() sys.stdout = sys.stderr = buf try: out = partial(prints, file=buf) @@ -82,16 +83,17 @@ def debug(): connected_devices = [] for dev in device_plugins(): out('Looking for', dev.__class__.__name__) - connected = s.is_device_connected(dev, debug=True) + connected, det = s.is_device_connected(dev, debug=True) if connected: - connected_devices.append(dev) + connected_devices.append((dev, det)) errors = {} success = False - for dev in connected_devices: + for dev, det in connected_devices: out('Device possibly connected:', dev.__class__.name) out('Trying to open device...', end=' ') try: + dev.reset(detected_device=det) dev.open() out('OK') except: @@ -112,11 +114,17 @@ def debug(): out(' ') if ioreg is not None: + ioreg = 'IOREG Output\n'+ioreg out(' ') - out('IOREG Output') - out(ioreg) + if ioreg_to_tmp: + open('/tmp/ioreg.txt', 'wb').write(ioreg) + out('Dont forget to send the contents of /tmp/ioreg.txt') + out('You can open it with the command: open /tmp/ioreg.txt') + else: + out(ioreg) - return buf.getvalue().decode('utf-8') + if hasattr(buf, 'getvalue'): + return buf.getvalue().decode('utf-8') finally: sys.stdout = oldo sys.stderr = olde diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index b1f748835c..e239699a4e 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -460,9 +460,9 @@ class Device(DeviceConfig, DevicePlugin): matches.sort(cmp=dcmp) drives = {'main':matches[0]} - if len(matches > 1): + if len(matches) > 1: drives['carda'] = matches[1] - if len(matches > 2): + if len(matches) > 2: drives['cardb'] = matches[2] return drives @@ -476,11 +476,13 @@ class Device(DeviceConfig, DevicePlugin): def open_osx(self): drives = self.osx_bsd_names() + bsd_drives = dict(**drives) drives = self.osx_sort_names(drives) mount_map = usbobserver.get_mounted_filesystems() for k, v in drives.items(): - drives[k] = mount_map.get(k, None) + drives[k] = mount_map.get(v, None) if drives['main'] is None: + print bsd_drives, mount_map, drives raise DeviceError(_('Unable to detect the %s mount point. Try rebooting.')%self.__class__.__name__) self._main_prefix = drives['main']+os.sep def get_card_prefix(c):