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
|
self.all_storage_ids = fs_cache.all_storage_ids
|
||||||
|
|
||||||
if self.storage_id not in self.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,
|
raise ValueError('Storage id %s not valid for %s, valid values: %s'%(self.storage_id,
|
||||||
entry))
|
entry, self.all_storage_ids))
|
||||||
|
|
||||||
if self.parent_id == 0:
|
if self.parent_id == 0:
|
||||||
self.parent_id = self.storage_id
|
self.parent_id = self.storage_id
|
||||||
@ -138,7 +138,7 @@ class FilesystemCache(object):
|
|||||||
self.entries.append(e)
|
self.entries.append(e)
|
||||||
|
|
||||||
self.entries.sort(key=attrgetter('object_id'))
|
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)
|
self.all_storage_ids = tuple(all_storage_ids)
|
||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
@ -320,11 +320,22 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
(obj.full_path, self.format_errorstack(errs)))
|
(obj.full_path, self.format_errorstack(errs)))
|
||||||
parent.remove_child(obj)
|
parent.remove_child(obj)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def develop():
|
||||||
class PR:
|
from calibre.devices.scanner import DeviceScanner
|
||||||
def report_progress(self, sent, total):
|
scanner = DeviceScanner()
|
||||||
print (sent, total, end=', ')
|
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 = MTP_DEVICE(None)
|
||||||
dev.startup()
|
dev.startup()
|
||||||
from calibre.devices.scanner import DeviceScanner
|
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) {
|
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);
|
ans = Py_BuildValue("{s:s, s:k, s:k, s:k, s:K, s:O}",
|
||||||
if (ans == NULL) return PyErr_NoMemory();
|
"name", nf->filename,
|
||||||
|
"id", nf->item_id,
|
||||||
// We explicitly populate the dictionary instead of using Py_BuildValue to
|
"parent_id", nf->parent_id,
|
||||||
// handle the numeric variables properly. Without this, for some reason the
|
"storage_id", storage_id,
|
||||||
// dict sometimes has incorrect values
|
"size", nf->filesize,
|
||||||
l = PyLong_FromUnsignedLong(nf->item_id);
|
"is_folder", (nf->filetype == LIBMTP_FILETYPE_FOLDER) ? Py_True : Py_False
|
||||||
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;
|
|
||||||
|
|
||||||
return ans;
|
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) {
|
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);
|
entry = build_file_metadata(f, storage_id);
|
||||||
if (entry == NULL) { ok = 0; }
|
if (entry == NULL) { ok = 0; }
|
||||||
else {
|
else {
|
||||||
PyList_Append(ans, entry);
|
if (PyList_Append(ans, entry) != 0) { ok = 0; }
|
||||||
Py_DECREF(entry);
|
Py_DECREF(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ PyObject* get_storage_info(IPortableDevice *device) { // {{{
|
|||||||
if (SUCCEEDED(values->GetUnsignedIntegerValue(WPD_STORAGE_ACCESS_CAPABILITY, &access)) && access == WPD_STORAGE_ACCESS_CAPABILITY_READWRITE) desc = Py_True;
|
if (SUCCEEDED(values->GetUnsignedIntegerValue(WPD_STORAGE_ACCESS_CAPABILITY, &access)) && access == WPD_STORAGE_ACCESS_CAPABILITY_READWRITE) desc = Py_True;
|
||||||
soid = PyUnicode_FromWideChar(object_ids[i], wcslen(object_ids[i]));
|
soid = PyUnicode_FromWideChar(object_ids[i], wcslen(object_ids[i]));
|
||||||
if (soid == NULL) { PyErr_NoMemory(); goto end; }
|
if (soid == NULL) { PyErr_NoMemory(); goto end; }
|
||||||
so = Py_BuildValue("{s:K,s:K,s:K,s:K,s:O,s:N}",
|
so = Py_BuildValue("{s:K, s:K, s:K, s:K, s:O, s:N}",
|
||||||
"capacity", capacity, "capacity_objects", capacity_objects, "free_space", free_space, "free_objects", free_objects, "rw", desc, "id", soid);
|
"capacity", capacity, "capacity_objects", capacity_objects, "free_space", free_space, "free_objects", free_objects, "rw", desc, "id", soid);
|
||||||
if (so == NULL) { PyErr_NoMemory(); goto end; }
|
if (so == NULL) { PyErr_NoMemory(); goto end; }
|
||||||
if (SUCCEEDED(values->GetStringValue(WPD_STORAGE_DESCRIPTION, &storage_desc))) {
|
if (SUCCEEDED(values->GetStringValue(WPD_STORAGE_DESCRIPTION, &storage_desc))) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user