mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix erroneuos method signature for new types defined in C extensions. Also fix handling of uint* types in the libusb and libmtp modules (I hope)
This commit is contained in:
parent
3ee0576ed4
commit
f0d7ad2635
@ -80,9 +80,9 @@ static PyObject* get_devices(PyObject *self, PyObject *args) {
|
||||
if (err != 0) { format_err(err); break; }
|
||||
if (desc.bDeviceClass == LIBUSB_CLASS_HUB) continue;
|
||||
|
||||
d = Py_BuildValue("(HHHHH)", libusb_get_bus_number(dev),
|
||||
libusb_get_device_address(dev), desc.idVendor, desc.idProduct,
|
||||
desc.bcdDevice);
|
||||
d = Py_BuildValue("(BBHHH)", (unsigned char)libusb_get_bus_number(dev),
|
||||
(unsigned char)libusb_get_device_address(dev), (unsigned short)desc.idVendor, (unsigned short)desc.idProduct,
|
||||
(unsigned short)desc.bcdDevice);
|
||||
if (d == NULL) break;
|
||||
|
||||
t = PyDict_GetItem(cache, d);
|
||||
|
@ -55,7 +55,7 @@ static int report_progress(uint64_t const sent, uint64_t const total, void const
|
||||
cb = (ProgressCallback *)data;
|
||||
if (cb->obj != NULL) {
|
||||
PyEval_RestoreThread(cb->state);
|
||||
res = PyObject_CallFunction(cb->obj, "KK", sent, total);
|
||||
res = PyObject_CallFunction(cb->obj, "KK", (unsigned long long)sent, (unsigned long long)total);
|
||||
Py_XDECREF(res);
|
||||
cb->state = PyEval_SaveThread();
|
||||
}
|
||||
@ -84,7 +84,7 @@ static uint16_t data_to_python(void *params, void *priv, uint32_t sendlen, unsig
|
||||
cb = (ProgressCallback *)priv;
|
||||
*putlen = sendlen;
|
||||
PyEval_RestoreThread(cb->state);
|
||||
res = PyObject_CallMethod(cb->extra, "write", "s#", data, sendlen);
|
||||
res = PyObject_CallMethod(cb->extra, "write", "s#", data, (Py_ssize_t)sendlen);
|
||||
if (res == NULL) {
|
||||
ret = LIBMTP_HANDLER_RETURN_ERROR;
|
||||
*putlen = 0;
|
||||
@ -106,7 +106,7 @@ static uint16_t data_from_python(void *params, void *priv, uint32_t wantlen, uns
|
||||
|
||||
cb = (ProgressCallback *)priv;
|
||||
PyEval_RestoreThread(cb->state);
|
||||
res = PyObject_CallMethod(cb->extra, "read", "k", wantlen);
|
||||
res = PyObject_CallMethod(cb->extra, "read", "k", (unsigned long)wantlen);
|
||||
if (res != NULL && PyBytes_AsStringAndSize(res, &buf, &len) != -1 && len <= wantlen) {
|
||||
memcpy(data, buf, len);
|
||||
*gotlen = len;
|
||||
@ -122,10 +122,10 @@ static PyObject* build_file_metadata(LIBMTP_file_t *nf, uint32_t storage_id) {
|
||||
PyObject *ans = NULL;
|
||||
|
||||
ans = Py_BuildValue("{s:s, s:k, s:k, s:k, s:K, s:O}",
|
||||
"name", nf->filename,
|
||||
"id", nf->item_id,
|
||||
"parent_id", nf->parent_id,
|
||||
"storage_id", storage_id,
|
||||
"name", (unsigned long)nf->filename,
|
||||
"id", (unsigned long)nf->item_id,
|
||||
"parent_id", (unsigned long)nf->parent_id,
|
||||
"storage_id", (unsigned long)storage_id,
|
||||
"size", nf->filesize,
|
||||
"is_folder", (nf->filetype == LIBMTP_FILETYPE_FOLDER) ? Py_True : Py_False
|
||||
);
|
||||
@ -161,11 +161,11 @@ typedef struct {
|
||||
PyObject *serial_number;
|
||||
PyObject *device_version;
|
||||
|
||||
} libmtp_Device;
|
||||
} Device;
|
||||
|
||||
// Device.__init__() {{{
|
||||
static void
|
||||
libmtp_Device_dealloc(libmtp_Device* self)
|
||||
Device_dealloc(Device* self)
|
||||
{
|
||||
if (self->device != NULL) {
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
@ -185,11 +185,11 @@ libmtp_Device_dealloc(libmtp_Device* self)
|
||||
}
|
||||
|
||||
static int
|
||||
libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
||||
Device_init(Device *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
uint32_t busnum;
|
||||
uint8_t devnum;
|
||||
uint16_t vendor_id, product_id;
|
||||
unsigned long busnum;
|
||||
unsigned char devnum;
|
||||
unsigned short vendor_id, product_id;
|
||||
PyObject *usb_serialnum;
|
||||
char *vendor, *product, *friendly_name, *manufacturer_name, *model_name, *serial_number, *device_version;
|
||||
LIBMTP_raw_device_t *rawdevs = NULL, rdev;
|
||||
@ -197,7 +197,7 @@ libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
||||
LIBMTP_mtpdevice_t *dev = NULL;
|
||||
LIBMTP_error_number_t err;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "IBHHssO", &busnum, &devnum, &vendor_id, &product_id, &vendor, &product, &usb_serialnum)) return -1;
|
||||
if (!PyArg_ParseTuple(args, "kBHHssO", &busnum, &devnum, &vendor_id, &product_id, &vendor, &product, &usb_serialnum)) return -1;
|
||||
|
||||
// We have to build and search the rawdevice list instead of creating a
|
||||
// rawdevice directly as otherwise, dynamic bug flag assignment in libmtp
|
||||
@ -212,7 +212,7 @@ libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
||||
|
||||
for (c = 0; c < numdevs; c++) {
|
||||
rdev = rawdevs[c];
|
||||
if (rdev.bus_location == busnum && rdev.devnum == devnum) {
|
||||
if (rdev.bus_location == (uint32_t)busnum && rdev.devnum == (uint8_t)devnum) {
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
dev = LIBMTP_Open_Raw_Device_Uncached(&rdev);
|
||||
Py_END_ALLOW_THREADS;
|
||||
@ -222,10 +222,10 @@ libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
||||
}
|
||||
|
||||
if (rawdevs != NULL) free(rawdevs);
|
||||
if (dev == NULL) { PyErr_Format(MTPError, "No device with busnum=%lu and devnum=%u found", (long unsigned int)busnum, devnum); return -1; }
|
||||
if (dev == NULL) { PyErr_Format(MTPError, "No device with busnum=%lu and devnum=%u found", busnum, devnum); return -1; }
|
||||
|
||||
self->device = dev;
|
||||
self->ids = Py_BuildValue("IBHHO", busnum, devnum, vendor_id, product_id, usb_serialnum);
|
||||
self->ids = Py_BuildValue("kBHHO", busnum, devnum, vendor_id, product_id, usb_serialnum);
|
||||
if (self->ids == NULL) return -1;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
@ -272,46 +272,46 @@ libmtp_Device_init(libmtp_Device *self, PyObject *args, PyObject *kwds)
|
||||
|
||||
// Device.friendly_name {{{
|
||||
static PyObject *
|
||||
libmtp_Device_friendly_name(libmtp_Device *self, void *closure) {
|
||||
Device_friendly_name(Device *self, void *closure) {
|
||||
Py_INCREF(self->friendly_name); return self->friendly_name;
|
||||
} // }}}
|
||||
|
||||
// Device.manufacturer_name {{{
|
||||
static PyObject *
|
||||
libmtp_Device_manufacturer_name(libmtp_Device *self, void *closure) {
|
||||
Device_manufacturer_name(Device *self, void *closure) {
|
||||
Py_INCREF(self->manufacturer_name); return self->manufacturer_name;
|
||||
} // }}}
|
||||
|
||||
// Device.model_name {{{
|
||||
static PyObject *
|
||||
libmtp_Device_model_name(libmtp_Device *self, void *closure) {
|
||||
Device_model_name(Device *self, void *closure) {
|
||||
Py_INCREF(self->model_name); return self->model_name;
|
||||
} // }}}
|
||||
|
||||
// Device.serial_number {{{
|
||||
static PyObject *
|
||||
libmtp_Device_serial_number(libmtp_Device *self, void *closure) {
|
||||
Device_serial_number(Device *self, void *closure) {
|
||||
Py_INCREF(self->serial_number); return self->serial_number;
|
||||
} // }}}
|
||||
|
||||
// Device.device_version {{{
|
||||
static PyObject *
|
||||
libmtp_Device_device_version(libmtp_Device *self, void *closure) {
|
||||
Device_device_version(Device *self, void *closure) {
|
||||
Py_INCREF(self->device_version); return self->device_version;
|
||||
} // }}}
|
||||
|
||||
// Device.ids {{{
|
||||
static PyObject *
|
||||
libmtp_Device_ids(libmtp_Device *self, void *closure) {
|
||||
Device_ids(Device *self, void *closure) {
|
||||
Py_INCREF(self->ids); return self->ids;
|
||||
} // }}}
|
||||
|
||||
// Device.update_storage_info() {{{
|
||||
static PyObject*
|
||||
libmtp_Device_update_storage_info(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
Device_update_storage_info(Device *self, PyObject *args) {
|
||||
ENSURE_DEV(NULL);
|
||||
if (LIBMTP_Get_Storage(self->device, LIBMTP_STORAGE_SORTBY_NOTSORTED) < 0) {
|
||||
PyErr_SetString(MTPError, "Failed to get storage infor for device.");
|
||||
PyErr_SetString(MTPError, "Failed to get storage info for device.");
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
@ -320,7 +320,7 @@ libmtp_Device_update_storage_info(libmtp_Device *self, PyObject *args, PyObject
|
||||
|
||||
// Device.storage_info {{{
|
||||
static PyObject *
|
||||
libmtp_Device_storage_info(libmtp_Device *self, void *closure) {
|
||||
Device_storage_info(Device *self, void *closure) {
|
||||
PyObject *ans, *loc;
|
||||
LIBMTP_devicestorage_t *storage;
|
||||
int ro = 0;
|
||||
@ -335,11 +335,11 @@ libmtp_Device_storage_info(libmtp_Device *self, void *closure) {
|
||||
if (storage->StorageType == ST_FixedROM || storage->StorageType == ST_RemovableROM || (storage->id & 0x0000FFFFU) == 0x00000000U || storage->AccessCapability == AC_ReadOnly || storage->AccessCapability == AC_ReadOnly_with_Object_Deletion) ro = 1;
|
||||
|
||||
loc = Py_BuildValue("{s:k,s:O,s:K,s:K,s:K,s:s,s:s,s:O}",
|
||||
"id", storage->id,
|
||||
"id", (unsigned long)storage->id,
|
||||
"removable", ((storage->StorageType == ST_RemovableRAM) ? Py_True : Py_False),
|
||||
"capacity", storage->MaxCapacity,
|
||||
"freespace_bytes", storage->FreeSpaceInBytes,
|
||||
"freespace_objects", storage->FreeSpaceInObjects,
|
||||
"capacity", (unsigned long long)storage->MaxCapacity,
|
||||
"freespace_bytes", (unsigned long long)storage->FreeSpaceInBytes,
|
||||
"freespace_objects", (unsigned long long)storage->FreeSpaceInObjects,
|
||||
"name", storage->StorageDescription,
|
||||
"volume_id", storage->VolumeIdentifier,
|
||||
"rw", (ro) ? Py_False : Py_True
|
||||
@ -392,9 +392,9 @@ static int recursive_get_files(LIBMTP_mtpdevice_t *dev, uint32_t storage_id, uin
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
libmtp_Device_get_filesystem(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
Device_get_filesystem(Device *self, PyObject *args) {
|
||||
PyObject *ans, *errs;
|
||||
uint32_t storage_id;
|
||||
unsigned long storage_id;
|
||||
int ok = 0;
|
||||
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
@ -405,7 +405,7 @@ libmtp_Device_get_filesystem(libmtp_Device *self, PyObject *args, PyObject *kwar
|
||||
if (errs == NULL || ans == NULL) { PyErr_NoMemory(); return NULL; }
|
||||
|
||||
LIBMTP_Clear_Errorstack(self->device);
|
||||
ok = recursive_get_files(self->device, storage_id, 0, ans, errs);
|
||||
ok = recursive_get_files(self->device, (uint32_t)storage_id, 0, ans, errs);
|
||||
dump_errorstack(self->device, errs);
|
||||
if (!ok) {
|
||||
Py_DECREF(ans);
|
||||
@ -419,10 +419,10 @@ libmtp_Device_get_filesystem(libmtp_Device *self, PyObject *args, PyObject *kwar
|
||||
|
||||
// Device.get_file {{{
|
||||
static PyObject *
|
||||
libmtp_Device_get_file(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
Device_get_file(Device *self, PyObject *args) {
|
||||
PyObject *stream, *callback = NULL, *errs;
|
||||
ProgressCallback cb;
|
||||
uint32_t fileid;
|
||||
unsigned long fileid;
|
||||
int ret;
|
||||
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
@ -436,7 +436,7 @@ libmtp_Device_get_file(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
cb.obj = callback; cb.extra = stream;
|
||||
Py_XINCREF(callback); Py_INCREF(stream);
|
||||
cb.state = PyEval_SaveThread();
|
||||
ret = LIBMTP_Get_File_To_Handler(self->device, fileid, data_to_python, &cb, report_progress, &cb);
|
||||
ret = LIBMTP_Get_File_To_Handler(self->device, (uint32_t)fileid, data_to_python, &cb, report_progress, &cb);
|
||||
PyEval_RestoreThread(cb.state);
|
||||
Py_XDECREF(callback); Py_DECREF(stream);
|
||||
|
||||
@ -450,11 +450,11 @@ libmtp_Device_get_file(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// Device.put_file {{{
|
||||
static PyObject *
|
||||
libmtp_Device_put_file(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
Device_put_file(Device *self, PyObject *args) {
|
||||
PyObject *stream, *callback = NULL, *errs, *fo = NULL;
|
||||
ProgressCallback cb;
|
||||
uint32_t parent_id, storage_id;
|
||||
uint64_t filesize;
|
||||
unsigned long parent_id, storage_id;
|
||||
unsigned long long filesize;
|
||||
int ret;
|
||||
char *name;
|
||||
LIBMTP_file_t f;
|
||||
@ -467,7 +467,7 @@ libmtp_Device_put_file(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
if (callback == NULL || !PyCallable_Check(callback)) callback = NULL;
|
||||
|
||||
cb.obj = callback; cb.extra = stream;
|
||||
f.parent_id = parent_id; f.storage_id = storage_id; f.item_id = 0; f.filename = name; f.filetype = LIBMTP_FILETYPE_UNKNOWN; f.filesize = filesize;
|
||||
f.parent_id = (uint32_t)parent_id; f.storage_id = (uint32_t)storage_id; f.item_id = 0; f.filename = name; f.filetype = LIBMTP_FILETYPE_UNKNOWN; f.filesize = (uint64_t)filesize;
|
||||
Py_XINCREF(callback); Py_INCREF(stream);
|
||||
cb.state = PyEval_SaveThread();
|
||||
ret = LIBMTP_Send_File_From_Handler(self->device, data_from_python, &cb, &f, report_progress, &cb);
|
||||
@ -484,9 +484,9 @@ libmtp_Device_put_file(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// Device.delete_object {{{
|
||||
static PyObject *
|
||||
libmtp_Device_delete_object(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
Device_delete_object(Device *self, PyObject *args) {
|
||||
PyObject *errs;
|
||||
uint32_t id;
|
||||
unsigned long id;
|
||||
int res;
|
||||
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
@ -496,7 +496,7 @@ libmtp_Device_delete_object(libmtp_Device *self, PyObject *args, PyObject *kwarg
|
||||
if (errs == NULL) { PyErr_NoMemory(); return NULL; }
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
res = LIBMTP_Delete_Object(self->device, id);
|
||||
res = LIBMTP_Delete_Object(self->device, (uint32_t)id);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (res != 0) dump_errorstack(self->device, errs);
|
||||
|
||||
@ -505,9 +505,10 @@ libmtp_Device_delete_object(libmtp_Device *self, PyObject *args, PyObject *kwarg
|
||||
|
||||
// Device.create_folder {{{
|
||||
static PyObject *
|
||||
libmtp_Device_create_folder(libmtp_Device *self, PyObject *args, PyObject *kwargs) {
|
||||
Device_create_folder(Device *self, PyObject *args) {
|
||||
PyObject *errs, *fo = NULL;
|
||||
uint32_t storage_id, parent_id, folder_id;
|
||||
unsigned long storage_id, parent_id;
|
||||
uint32_t folder_id;
|
||||
char *name;
|
||||
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
@ -517,7 +518,7 @@ libmtp_Device_create_folder(libmtp_Device *self, PyObject *args, PyObject *kwarg
|
||||
if (errs == NULL) { PyErr_NoMemory(); return NULL; }
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
folder_id = LIBMTP_Create_Folder(self->device, name, parent_id, storage_id);
|
||||
folder_id = LIBMTP_Create_Folder(self->device, name, (uint32_t)parent_id, (uint32_t)storage_id);
|
||||
Py_END_ALLOW_THREADS;
|
||||
|
||||
if (folder_id == 0) dump_errorstack(self->device, errs);
|
||||
@ -527,28 +528,28 @@ libmtp_Device_create_folder(libmtp_Device *self, PyObject *args, PyObject *kwarg
|
||||
return Py_BuildValue("NN", fo, errs);
|
||||
} // }}}
|
||||
|
||||
static PyMethodDef libmtp_Device_methods[] = {
|
||||
{"update_storage_info", (PyCFunction)libmtp_Device_update_storage_info, METH_VARARGS,
|
||||
static PyMethodDef Device_methods[] = {
|
||||
{"update_storage_info", (PyCFunction)Device_update_storage_info, METH_VARARGS,
|
||||
"update_storage_info() -> Reread the storage info from the device (total, space, free space, storage locations, etc.)"
|
||||
},
|
||||
|
||||
{"get_filesystem", (PyCFunction)libmtp_Device_get_filesystem, METH_VARARGS,
|
||||
{"get_filesystem", (PyCFunction)Device_get_filesystem, METH_VARARGS,
|
||||
"get_filesystem(storage_id) -> Get the list of files and folders on the device in storage_id. Returns files, errors."
|
||||
},
|
||||
|
||||
{"get_file", (PyCFunction)libmtp_Device_get_file, METH_VARARGS,
|
||||
{"get_file", (PyCFunction)Device_get_file, METH_VARARGS,
|
||||
"get_file(fileid, stream, callback=None) -> Get the file specified by fileid from the device. stream must be a file-like object. The file will be written to it. callback works the same as in get_filelist(). Returns ok, errs, where errs is a list of errors (if any)."
|
||||
},
|
||||
|
||||
{"put_file", (PyCFunction)libmtp_Device_put_file, METH_VARARGS,
|
||||
{"put_file", (PyCFunction)Device_put_file, METH_VARARGS,
|
||||
"put_file(storage_id, parent_id, filename, stream, size, callback=None) -> Put a file on the device. The file is read from stream. It is put inside the folder identified by parent_id on the storage identified by storage_id. Use parent_id=0 to put it in the root. stream must be a file-like object. size is the size in bytes of the data in stream. callback works the same as in get_filelist(). Returns fileinfo, errs, where errs is a list of errors (if any), and fileinfo is a file information dictionary, as returned by get_filelist(). fileinfo will be None if case or errors."
|
||||
},
|
||||
|
||||
{"create_folder", (PyCFunction)libmtp_Device_create_folder, METH_VARARGS,
|
||||
{"create_folder", (PyCFunction)Device_create_folder, METH_VARARGS,
|
||||
"create_folder(storage_id, parent_id, name) -> Create a folder named name under parent parent_id (use 0 for root) in the storage identified by storage_id. Returns folderinfo, errors, where folderinfo is the same dict as returned by get_folderlist(), it will be None if there are errors."
|
||||
},
|
||||
|
||||
{"delete_object", (PyCFunction)libmtp_Device_delete_object, METH_VARARGS,
|
||||
{"delete_object", (PyCFunction)Device_delete_object, METH_VARARGS,
|
||||
"delete_object(id) -> Delete the object identified by id from the device. Can be used to delete files, folders, etc. Returns ok, errs."
|
||||
},
|
||||
|
||||
@ -556,52 +557,52 @@ static PyMethodDef libmtp_Device_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyGetSetDef libmtp_Device_getsetters[] = {
|
||||
static PyGetSetDef Device_getsetters[] = {
|
||||
{(char *)"friendly_name",
|
||||
(getter)libmtp_Device_friendly_name, NULL,
|
||||
(getter)Device_friendly_name, NULL,
|
||||
(char *)"The friendly name of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"manufacturer_name",
|
||||
(getter)libmtp_Device_manufacturer_name, NULL,
|
||||
(getter)Device_manufacturer_name, NULL,
|
||||
(char *)"The manufacturer name of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"model_name",
|
||||
(getter)libmtp_Device_model_name, NULL,
|
||||
(getter)Device_model_name, NULL,
|
||||
(char *)"The model name of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"serial_number",
|
||||
(getter)libmtp_Device_serial_number, NULL,
|
||||
(getter)Device_serial_number, NULL,
|
||||
(char *)"The serial number of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"device_version",
|
||||
(getter)libmtp_Device_device_version, NULL,
|
||||
(getter)Device_device_version, NULL,
|
||||
(char *)"The device version of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"ids",
|
||||
(getter)libmtp_Device_ids, NULL,
|
||||
(getter)Device_ids, NULL,
|
||||
(char *)"The ids of the device (busnum, devnum, vendor_id, product_id, usb_serialnum)",
|
||||
NULL},
|
||||
|
||||
{(char *)"storage_info",
|
||||
(getter)libmtp_Device_storage_info, NULL,
|
||||
(getter)Device_storage_info, NULL,
|
||||
(char *)"Information about the storage locations on the device. Returns a list of dictionaries where each dictionary corresponds to the LIBMTP_devicestorage_struct.",
|
||||
NULL},
|
||||
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyTypeObject libmtp_DeviceType = { // {{{
|
||||
static PyTypeObject DeviceType = { // {{{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"libmtp.Device", /*tp_name*/
|
||||
sizeof(libmtp_Device), /*tp_basicsize*/
|
||||
sizeof(Device), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)libmtp_Device_dealloc, /*tp_dealloc*/
|
||||
(destructor)Device_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
@ -624,15 +625,15 @@ static PyTypeObject libmtp_DeviceType = { // {{{
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
libmtp_Device_methods, /* tp_methods */
|
||||
Device_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
libmtp_Device_getsetters, /* tp_getset */
|
||||
Device_getsetters, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)libmtp_Device_init, /* tp_init */
|
||||
(initproc)Device_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
0, /* tp_new */
|
||||
}; // }}}
|
||||
@ -640,7 +641,7 @@ static PyTypeObject libmtp_DeviceType = { // {{{
|
||||
// }}} End Device object definition
|
||||
|
||||
static PyObject *
|
||||
libmtp_set_debug_level(PyObject *self, PyObject *args) {
|
||||
set_debug_level(PyObject *self, PyObject *args) {
|
||||
int level;
|
||||
if (!PyArg_ParseTuple(args, "i", &level)) return NULL;
|
||||
LIBMTP_Set_Debug(level);
|
||||
@ -649,18 +650,10 @@ libmtp_set_debug_level(PyObject *self, PyObject *args) {
|
||||
|
||||
|
||||
static PyObject *
|
||||
libmtp_is_mtp_device(PyObject *self, PyObject *args) {
|
||||
int busnum, devnum, vendor_id, prod_id, ans = 0;
|
||||
size_t i;
|
||||
is_mtp_device(PyObject *self, PyObject *args) {
|
||||
int busnum, devnum, ans = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iiii", &busnum, &devnum, &vendor_id, &prod_id)) return NULL;
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
if (calibre_mtp_device_table[i].vendor == NULL && calibre_mtp_device_table[i].product == NULL && calibre_mtp_device_table[i].vendor_id == 0xffff) break;
|
||||
if (calibre_mtp_device_table[i].vendor_id == vendor_id && calibre_mtp_device_table[i].product_id == prod_id) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
}
|
||||
if (!PyArg_ParseTuple(args, "ii", &busnum, &devnum)) return NULL;
|
||||
|
||||
/*
|
||||
* LIBMTP_Check_Specific_Device does not seem to work at least on my linux
|
||||
@ -689,7 +682,7 @@ known_devices(PyObject *self, PyObject *args) {
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
if (calibre_mtp_device_table[i].vendor == NULL && calibre_mtp_device_table[i].product == NULL && calibre_mtp_device_table[i].vendor_id == 0xffff) break;
|
||||
d = Py_BuildValue("(HH)", calibre_mtp_device_table[i].vendor_id, calibre_mtp_device_table[i].product_id);
|
||||
d = Py_BuildValue("(HH)", (unsigned short)calibre_mtp_device_table[i].vendor_id, (unsigned short)calibre_mtp_device_table[i].product_id);
|
||||
if (d == NULL) { Py_DECREF(ans); ans = NULL; break; }
|
||||
if (PyList_Append(ans, d) != 0) { Py_DECREF(d); Py_DECREF(ans); ans = NULL; PyErr_NoMemory(); break; }
|
||||
Py_DECREF(d);
|
||||
@ -699,12 +692,12 @@ known_devices(PyObject *self, PyObject *args) {
|
||||
}
|
||||
|
||||
static PyMethodDef libmtp_methods[] = {
|
||||
{"set_debug_level", libmtp_set_debug_level, METH_VARARGS,
|
||||
{"set_debug_level", set_debug_level, METH_VARARGS,
|
||||
"set_debug_level(level)\n\nSet the debug level bit mask, see LIBMTP_DEBUG_* constants."
|
||||
},
|
||||
|
||||
{"is_mtp_device", libmtp_is_mtp_device, METH_VARARGS,
|
||||
"is_mtp_device(busnum, devnum, vendor_id, prod_id)\n\nReturn True if the device is recognized as an MTP device by its vendor/product ids. If it is not recognized a probe is done and True returned if the probe succeeds. Note that probing can cause some devices to malfunction, and it is not very reliable, which is why we prefer to use the device database."
|
||||
{"is_mtp_device", is_mtp_device, METH_VARARGS,
|
||||
"is_mtp_device(busnum, devnum)\n\nA probe is done and True returned if the probe succeeds. Note that probing can cause some devices to malfunction, and it is not very reliable, which is why we prefer to use the device database."
|
||||
},
|
||||
|
||||
{"known_devices", known_devices, METH_VARARGS,
|
||||
@ -719,8 +712,8 @@ PyMODINIT_FUNC
|
||||
initlibmtp(void) {
|
||||
PyObject *m;
|
||||
|
||||
libmtp_DeviceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&libmtp_DeviceType) < 0)
|
||||
DeviceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&DeviceType) < 0)
|
||||
return;
|
||||
|
||||
m = Py_InitModule3("libmtp", libmtp_methods, "Interface to libmtp.");
|
||||
@ -733,8 +726,8 @@ initlibmtp(void) {
|
||||
LIBMTP_Init();
|
||||
LIBMTP_Set_Debug(LIBMTP_DEBUG_NONE);
|
||||
|
||||
Py_INCREF(&libmtp_DeviceType);
|
||||
PyModule_AddObject(m, "Device", (PyObject *)&libmtp_DeviceType);
|
||||
Py_INCREF(&DeviceType);
|
||||
PyModule_AddObject(m, "Device", (PyObject *)&DeviceType);
|
||||
|
||||
PyModule_AddStringMacro(m, LIBMTP_VERSION_STRING);
|
||||
PyModule_AddIntMacro(m, LIBMTP_DEBUG_NONE);
|
||||
|
@ -67,7 +67,7 @@ init(Device *self, PyObject *args, PyObject *kwds)
|
||||
|
||||
// update_device_data() {{{
|
||||
static PyObject*
|
||||
update_data(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
update_data(Device *self, PyObject *args) {
|
||||
PyObject *di = NULL;
|
||||
di = get_device_information(self->device, NULL);
|
||||
if (di == NULL) return NULL;
|
||||
@ -77,7 +77,7 @@ update_data(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// get_filesystem() {{{
|
||||
static PyObject*
|
||||
py_get_filesystem(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
py_get_filesystem(Device *self, PyObject *args) {
|
||||
PyObject *storage_id, *ret;
|
||||
wchar_t *storage;
|
||||
|
||||
@ -92,7 +92,7 @@ py_get_filesystem(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// get_file() {{{
|
||||
static PyObject*
|
||||
py_get_file(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
py_get_file(Device *self, PyObject *args) {
|
||||
PyObject *object_id, *stream, *callback = NULL, *ret;
|
||||
wchar_t *object;
|
||||
|
||||
@ -109,7 +109,7 @@ py_get_file(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// create_folder() {{{
|
||||
static PyObject*
|
||||
py_create_folder(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
py_create_folder(Device *self, PyObject *args) {
|
||||
PyObject *pparent_id, *pname, *ret;
|
||||
wchar_t *parent_id, *name;
|
||||
|
||||
@ -125,7 +125,7 @@ py_create_folder(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// delete_object() {{{
|
||||
static PyObject*
|
||||
py_delete_object(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
py_delete_object(Device *self, PyObject *args) {
|
||||
PyObject *pobject_id, *ret;
|
||||
wchar_t *object_id;
|
||||
|
||||
@ -140,10 +140,10 @@ py_delete_object(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// get_file() {{{
|
||||
static PyObject*
|
||||
py_put_file(Device *self, PyObject *args, PyObject *kwargs) {
|
||||
py_put_file(Device *self, PyObject *args) {
|
||||
PyObject *pparent_id, *pname, *stream, *callback = NULL, *ret;
|
||||
wchar_t *parent_id, *name;
|
||||
unsigned PY_LONG_LONG size;
|
||||
unsigned long long size;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOOK|O", &pparent_id, &pname, &stream, &size, &callback)) return NULL;
|
||||
parent_id = unicode_to_wchar(pparent_id);
|
||||
|
@ -34,7 +34,7 @@ PDFDoc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
|
||||
// Loading/Opening of PDF files {{{
|
||||
static PyObject *
|
||||
PDFDoc_load(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_load(PDFDoc *self, PyObject *args) {
|
||||
char *buffer; Py_ssize_t size;
|
||||
|
||||
if (PyArg_ParseTuple(args, "s#", &buffer, &size)) {
|
||||
@ -51,7 +51,7 @@ PDFDoc_load(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PDFDoc_open(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_open(PDFDoc *self, PyObject *args) {
|
||||
char *fname;
|
||||
|
||||
if (PyArg_ParseTuple(args, "s", &fname)) {
|
||||
@ -70,7 +70,7 @@ PDFDoc_open(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// Saving/writing of PDF files {{{
|
||||
static PyObject *
|
||||
PDFDoc_save(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_save(PDFDoc *self, PyObject *args) {
|
||||
char *buffer;
|
||||
|
||||
if (PyArg_ParseTuple(args, "s", &buffer)) {
|
||||
@ -86,7 +86,7 @@ PDFDoc_save(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PDFDoc_write(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_write(PDFDoc *self, PyObject *args) {
|
||||
PyObject *ans;
|
||||
|
||||
try {
|
||||
@ -108,7 +108,7 @@ PDFDoc_write(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// extract_first_page() {{{
|
||||
static PyObject *
|
||||
PDFDoc_extract_first_page(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_extract_first_page(PDFDoc *self, PyObject *args) {
|
||||
try {
|
||||
while (self->doc->GetPageCount() > 1) self->doc->GetPagesTree()->DeletePage(1);
|
||||
} catch(const PdfError & err) {
|
||||
@ -121,7 +121,7 @@ PDFDoc_extract_first_page(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// page_count() {{{
|
||||
static PyObject *
|
||||
PDFDoc_page_count(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_page_count(PDFDoc *self, PyObject *args) {
|
||||
int count;
|
||||
try {
|
||||
count = self->doc->GetPageCount();
|
||||
@ -134,7 +134,7 @@ PDFDoc_page_count(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// delete_page {{{
|
||||
static PyObject *
|
||||
PDFDoc_delete_page(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_delete_page(PDFDoc *self, PyObject *args) {
|
||||
int num = 0;
|
||||
if (PyArg_ParseTuple(args, "i", &num)) {
|
||||
try {
|
||||
@ -150,7 +150,7 @@ PDFDoc_delete_page(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// append() {{{
|
||||
static PyObject *
|
||||
PDFDoc_append(PDFDoc *self, PyObject *args, PyObject *kwargs) {
|
||||
PDFDoc_append(PDFDoc *self, PyObject *args) {
|
||||
PyObject *doc;
|
||||
int typ;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user