mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
9aa30a8b71
commit
f9dc2cd6d7
@ -31,8 +31,8 @@ class FileOrFolder(object):
|
||||
self.all_storage_ids = fs_cache.all_storage_ids
|
||||
|
||||
if self.storage_id not in self.all_storage_ids:
|
||||
raise ValueError('Storage id %s not valid for %s'%(self.storage_id,
|
||||
entry))
|
||||
raise ValueError('Storage id %s not valid for %s, valid values: %s'%(self.storage_id,
|
||||
entry, self.all_storage_ids))
|
||||
|
||||
if self.parent_id == 0:
|
||||
self.parent_id = self.storage_id
|
||||
@ -138,7 +138,7 @@ class FilesystemCache(object):
|
||||
self.entries.append(e)
|
||||
|
||||
self.entries.sort(key=attrgetter('object_id'))
|
||||
all_storage_ids = [x.object_id for x in self.entries]
|
||||
all_storage_ids = [x.storage_id for x in self.entries]
|
||||
self.all_storage_ids = tuple(all_storage_ids)
|
||||
|
||||
for entry in entries:
|
||||
|
@ -320,11 +320,22 @@ class MTP_DEVICE(MTPDeviceBase):
|
||||
(obj.full_path, self.format_errorstack(errs)))
|
||||
parent.remove_child(obj)
|
||||
|
||||
if __name__ == '__main__':
|
||||
class PR:
|
||||
def report_progress(self, sent, total):
|
||||
print (sent, total, end=', ')
|
||||
def develop():
|
||||
from calibre.devices.scanner import DeviceScanner
|
||||
scanner = DeviceScanner()
|
||||
scanner.scan()
|
||||
dev = MTP_DEVICE(None)
|
||||
dev.startup()
|
||||
try:
|
||||
cd = dev.detect_managed_devices(scanner.devices)
|
||||
if cd is None: raise RuntimeError('No MTP device found')
|
||||
dev.open(cd, 'develop')
|
||||
pprint.pprint(dev.dev.storage_info)
|
||||
dev.filesystem_cache
|
||||
finally:
|
||||
dev.shutdown()
|
||||
|
||||
if __name__ == '__main__':
|
||||
dev = MTP_DEVICE(None)
|
||||
dev.startup()
|
||||
from calibre.devices.scanner import DeviceScanner
|
||||
|
@ -119,43 +119,18 @@ static uint16_t data_from_python(void *params, void *priv, uint32_t wantlen, uns
|
||||
}
|
||||
|
||||
static PyObject* build_file_metadata(LIBMTP_file_t *nf, uint32_t storage_id) {
|
||||
PyObject *ans = NULL, *l = NULL;
|
||||
PyObject *ans = NULL;
|
||||
|
||||
ans = Py_BuildValue("{s:s}", "name", nf->filename);
|
||||
if (ans == NULL) return PyErr_NoMemory();
|
||||
|
||||
// We explicitly populate the dictionary instead of using Py_BuildValue to
|
||||
// handle the numeric variables properly. Without this, for some reason the
|
||||
// dict sometimes has incorrect values
|
||||
l = PyLong_FromUnsignedLong(nf->item_id);
|
||||
if (l == NULL) goto error;
|
||||
if (PyDict_SetItemString(ans, "id", l) != 0) goto error;
|
||||
Py_DECREF(l); l = NULL;
|
||||
|
||||
l = PyLong_FromUnsignedLong(nf->parent_id);
|
||||
if (l == NULL) goto error;
|
||||
if (PyDict_SetItemString(ans, "parent_id", l) != 0) goto error;
|
||||
Py_DECREF(l); l = NULL;
|
||||
|
||||
l = PyLong_FromUnsignedLong(storage_id);
|
||||
if (l == NULL) goto error;
|
||||
if (PyDict_SetItemString(ans, "storage_id", l) != 0) goto error;
|
||||
Py_DECREF(l); l = NULL;
|
||||
|
||||
l = PyLong_FromUnsignedLongLong(nf->filesize);
|
||||
if (l == NULL) goto error;
|
||||
if (PyDict_SetItemString(ans, "size", l) != 0) goto error;
|
||||
Py_DECREF(l); l = NULL;
|
||||
|
||||
if (PyDict_SetItemString(ans, "is_folder",
|
||||
(nf->filetype == LIBMTP_FILETYPE_FOLDER) ? Py_True : Py_False) != 0)
|
||||
goto error;
|
||||
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,
|
||||
"size", nf->filesize,
|
||||
"is_folder", (nf->filetype == LIBMTP_FILETYPE_FOLDER) ? Py_True : Py_False
|
||||
);
|
||||
|
||||
return ans;
|
||||
|
||||
error:
|
||||
Py_XDECREF(ans); Py_XDECREF(l);
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
|
||||
static PyObject* file_metadata(LIBMTP_mtpdevice_t *device, PyObject *errs, uint32_t item_id, uint32_t storage_id) {
|
||||
@ -396,7 +371,7 @@ static int recursive_get_files(LIBMTP_mtpdevice_t *dev, uint32_t storage_id, uin
|
||||
entry = build_file_metadata(f, storage_id);
|
||||
if (entry == NULL) { ok = 0; }
|
||||
else {
|
||||
PyList_Append(ans, entry);
|
||||
if (PyList_Append(ans, entry) != 0) { ok = 0; }
|
||||
Py_DECREF(entry);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user