From 2aed6ba715491837cad19dfa4515ed80c6fd74d0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 19 Jul 2014 09:14:00 +0530 Subject: [PATCH] Add support for MTP devices on OS X --- manual/faq.rst | 6 +++--- src/calibre/devices/mtp/unix/driver.py | 24 ++++++++++++++++++++++-- src/calibre/devices/scanner.py | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/manual/faq.rst b/manual/faq.rst index a8ec8ce038..bad1ed467c 100644 --- a/manual/faq.rst +++ b/manual/faq.rst @@ -374,9 +374,9 @@ single android device out there, so if your device is not automatically detected, follow the instructions at :ref:`devsupport` to get your device supported in |app|. -.. note:: With newer Android devices, the USB connection is only supported on - Windows Vista and newer and Linux. If you are on Windows XP or OS X, - you should use one of the wireless connection methods. +.. note:: With newer Android devices, the USB connection is not supported on + Windows XP. If you are on Windows XP, you should use one of the + wireless connection methods. Over the air ^^^^^^^^^^^^^^ diff --git a/src/calibre/devices/mtp/unix/driver.py b/src/calibre/devices/mtp/unix/driver.py index fa23268336..10fff92127 100644 --- a/src/calibre/devices/mtp/unix/driver.py +++ b/src/calibre/devices/mtp/unix/driver.py @@ -13,7 +13,7 @@ from collections import namedtuple from functools import partial from calibre import prints, as_unicode -from calibre.constants import plugins, islinux +from calibre.constants import plugins, islinux, isosx from calibre.ptempfile import SpooledTemporaryFile from calibre.devices.errors import OpenFailed, DeviceError, BlacklistedDevice from calibre.devices.mtp.base import MTPDeviceBase, synchronous, debug @@ -31,7 +31,7 @@ APPLE = 0x05ac class MTP_DEVICE(MTPDeviceBase): # libusb(x) does not work on OS X. So no MTP support for OS X - supported_platforms = ['linux'] + supported_platforms = ['linux', 'osx'] def __init__(self, *args, **kwargs): MTPDeviceBase.__init__(self, *args, **kwargs) @@ -49,6 +49,11 @@ class MTP_DEVICE(MTPDeviceBase): if islinux: from calibre.devices.mtp.unix.sysfs import MTPDetect self._is_device_mtp = MTPDetect() + if isosx and 'osx' in self.supported_platforms: + self.usbobserver, err = plugins['usbobserver'] + if err: + raise RuntimeError(err) + self._is_device_mtp = self.osx_is_device_mtp def is_device_mtp(self, d, debug=None): ''' Returns True iff the _is_device_mtp check returns True and libmtp @@ -58,6 +63,21 @@ class MTP_DEVICE(MTPDeviceBase): return (self._is_device_mtp(d, debug=debug) and self.libmtp.is_mtp_device(d.busnum, d.devnum)) + def osx_is_device_mtp(self, d, debug=None): + if not d.serial: + ans = False + else: + try: + ans = self.usbobserver.is_mtp_device(d.vendor_id, d.product_id, d.bcd, d.serial) + except Exception: + if debug is not None: + import traceback + traceback.print_stack() + return False + if debug is not None and ans: + debug('Device {0} claims to be an MTP device in the IOKit registry'.format(d)) + return bool(ans) + def set_debug_level(self, lvl): self.libmtp.set_debug_level(lvl) diff --git a/src/calibre/devices/scanner.py b/src/calibre/devices/scanner.py index 541dc14829..3c99e7fab5 100644 --- a/src/calibre/devices/scanner.py +++ b/src/calibre/devices/scanner.py @@ -291,7 +291,7 @@ if islinux: linux_scanner = LinuxScanner() libusb_scanner = LibUSBScanner() -if isosx: +if False and isosx: # Apparently libusb causes mem leaks on some Macs and hangs on others and # works on a few. OS X users will just have to live without MTP support. # See https://bugs.launchpad.net/calibre/+bug/1044706