mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
3cc8ef1875
commit
9a25f5c023
@ -12,7 +12,7 @@ from threading import RLock
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints, as_unicode
|
||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
from calibre.ptempfile import SpooledTemporaryFile
|
from calibre.ptempfile import SpooledTemporaryFile
|
||||||
from calibre.devices.errors import OpenFailed, DeviceError
|
from calibre.devices.errors import OpenFailed, DeviceError
|
||||||
@ -28,7 +28,7 @@ def fingerprint(d):
|
|||||||
|
|
||||||
class MTP_DEVICE(MTPDeviceBase):
|
class MTP_DEVICE(MTPDeviceBase):
|
||||||
|
|
||||||
supported_platforms = ['linux']
|
supported_platforms = ['linux', 'osx']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
MTPDeviceBase.__init__(self, *args, **kwargs)
|
MTPDeviceBase.__init__(self, *args, **kwargs)
|
||||||
@ -138,11 +138,12 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
try:
|
try:
|
||||||
self.dev = self.create_device(connected_device)
|
self.dev = self.create_device(connected_device)
|
||||||
except self.libmtp.MTPError:
|
except self.libmtp.MTPError as e:
|
||||||
# Black list this device so that it is ignored for the
|
# Black list this device so that it is ignored for the
|
||||||
# remainder of this session.
|
# remainder of this session.
|
||||||
self.blacklisted_devices.add(connected_device)
|
self.blacklisted_devices.add(connected_device)
|
||||||
raise OpenFailed('%s is not a MTP device'%(connected_device,))
|
raise OpenFailed('Failed to open %s: Error: %s'%(
|
||||||
|
connected_device, as_unicode(e)))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.blacklisted_devices.add(connected_device)
|
self.blacklisted_devices.add(connected_device)
|
||||||
raise OpenFailed('')
|
raise OpenFailed('')
|
||||||
@ -309,9 +310,13 @@ if __name__ == '__main__':
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
dev = MTP_DEVICE(None)
|
dev = MTP_DEVICE(None)
|
||||||
dev.startup()
|
dev.startup()
|
||||||
from calibre.devices.scanner import linux_scanner
|
from calibre.devices.scanner import DeviceScanner
|
||||||
devs = linux_scanner()
|
scanner = DeviceScanner()
|
||||||
|
scanner.scan()
|
||||||
|
devs = scanner.devices
|
||||||
cd = dev.detect_managed_devices(devs)
|
cd = dev.detect_managed_devices(devs)
|
||||||
|
if cd is None:
|
||||||
|
raise Exception('No MTP device found')
|
||||||
dev.open(cd, 'xxx')
|
dev.open(cd, 'xxx')
|
||||||
d = dev.dev
|
d = dev.dev
|
||||||
print ("Opened device:", dev.get_gui_name())
|
print ("Opened device:", dev.get_gui_name())
|
||||||
|
@ -212,22 +212,24 @@ libmtp_Device_dealloc(libmtp_Device* self)
|
|||||||
static int
|
static int
|
||||||
libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
int busnum, devnum, vendor_id, product_id;
|
uint32_t busnum;
|
||||||
|
uint8_t devnum;
|
||||||
|
uint16_t vendor_id, product_id;
|
||||||
PyObject *usb_serialnum;
|
PyObject *usb_serialnum;
|
||||||
char *vendor, *product, *friendly_name, *manufacturer_name, *model_name, *serial_number, *device_version;
|
char *vendor, *product, *friendly_name, *manufacturer_name, *model_name, *serial_number, *device_version;
|
||||||
LIBMTP_raw_device_t rawdev;
|
LIBMTP_raw_device_t rawdev;
|
||||||
LIBMTP_mtpdevice_t *dev;
|
LIBMTP_mtpdevice_t *dev;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "iiiissO", &busnum, &devnum, &vendor_id, &product_id, &vendor, &product, &usb_serialnum)) return -1;
|
if (!PyArg_ParseTuple(args, "IBHHssO", &busnum, &devnum, &vendor_id, &product_id, &vendor, &product, &usb_serialnum)) return -1;
|
||||||
|
|
||||||
if (devnum < 0 || devnum > 255 || busnum < 0) { PyErr_SetString(PyExc_TypeError, "Invalid busnum/devnum"); return -1; }
|
if (devnum < 0 || devnum > 255 || busnum < 0) { PyErr_SetString(PyExc_TypeError, "Invalid busnum/devnum"); return -1; }
|
||||||
|
|
||||||
self->ids = Py_BuildValue("iiiiO", busnum, devnum, vendor_id, product_id, usb_serialnum);
|
self->ids = Py_BuildValue("IBHHO", busnum, devnum, vendor_id, product_id, usb_serialnum);
|
||||||
if (self->ids == NULL) return -1;
|
if (self->ids == NULL) return -1;
|
||||||
|
|
||||||
rawdev.bus_location = (uint32_t)busnum;
|
rawdev.bus_location = busnum;
|
||||||
rawdev.devnum = (uint8_t)devnum;
|
rawdev.devnum = devnum;
|
||||||
rawdev.device_entry.vendor = vendor;
|
rawdev.device_entry.vendor = vendor;
|
||||||
rawdev.device_entry.product = product;
|
rawdev.device_entry.product = product;
|
||||||
rawdev.device_entry.vendor_id = vendor_id;
|
rawdev.device_entry.vendor_id = vendor_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user