mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ebook-device: Implement the list command for MTP devices
This commit is contained in:
parent
cac3d25e03
commit
caf41ce8b1
@ -145,6 +145,34 @@ class MTP_DEVICE(BASE):
|
|||||||
self.current_device_defaults, self.current_vid, self.current_pid = self.device_defaults(device, self)
|
self.current_device_defaults, self.current_vid, self.current_pid = self.device_defaults(device, self)
|
||||||
self.calibre_file_paths = self.current_device_defaults.get(
|
self.calibre_file_paths = self.current_device_defaults.get(
|
||||||
'calibre_file_paths', {'metadata':self.METADATA_CACHE, 'driveinfo':self.DRIVEINFO})
|
'calibre_file_paths', {'metadata':self.METADATA_CACHE, 'driveinfo':self.DRIVEINFO})
|
||||||
|
if self.current_vid == 0x1949:
|
||||||
|
try:
|
||||||
|
self.sync_kindle_thumbnails()
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
def sync_kindle_thumbnails(self):
|
||||||
|
raise NotImplementedError('TODO: Implement me')
|
||||||
|
|
||||||
|
def list(self, path, recurse=False):
|
||||||
|
if path.startswith('/'):
|
||||||
|
q = self._main_id
|
||||||
|
path = path[1:]
|
||||||
|
elif path.startswith('card:/'):
|
||||||
|
q = self._carda_id
|
||||||
|
path = path[6:]
|
||||||
|
for storage in self.filesystem_cache.entries:
|
||||||
|
if storage.storage_id == q:
|
||||||
|
if path:
|
||||||
|
path = path.replace(os.sep, '/')
|
||||||
|
parts = path.split('/')
|
||||||
|
if parts:
|
||||||
|
storage = storage.find_path(parts)
|
||||||
|
if storage is None:
|
||||||
|
return []
|
||||||
|
return list(storage.list(recurse))
|
||||||
|
return []
|
||||||
|
|
||||||
def get_device_uid(self):
|
def get_device_uid(self):
|
||||||
return self.current_serial_num
|
return self.current_serial_num
|
||||||
|
@ -7,9 +7,11 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import weakref
|
import weakref
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from itertools import chain
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
from calibre import force_unicode, human_readable, prints
|
from calibre import force_unicode, human_readable, prints
|
||||||
@ -21,6 +23,17 @@ from polyglot.builtins import itervalues
|
|||||||
bexts = frozenset(BOOK_EXTENSIONS) - {'mbp', 'tan', 'rar', 'zip', 'xml'}
|
bexts = frozenset(BOOK_EXTENSIONS) - {'mbp', 'tan', 'rar', 'zip', 'xml'}
|
||||||
|
|
||||||
|
|
||||||
|
class ListEntry:
|
||||||
|
|
||||||
|
def __init__(self, entry: 'FileOrFolder'):
|
||||||
|
self.is_dir = entry.is_folder
|
||||||
|
self.is_readonly = not entry.can_delete
|
||||||
|
self.path = '/'.join(entry.full_path)
|
||||||
|
self.name = entry.name
|
||||||
|
self.size = entry.size
|
||||||
|
self.ctime = self.wtime = time.mktime(entry.last_modified.timetuple())
|
||||||
|
|
||||||
|
|
||||||
class FileOrFolder:
|
class FileOrFolder:
|
||||||
|
|
||||||
def __init__(self, entry, fs_cache):
|
def __init__(self, entry, fs_cache):
|
||||||
@ -139,6 +152,17 @@ class FileOrFolder:
|
|||||||
for e in sorted(c, key=lambda x:sort_key(x.name)):
|
for e in sorted(c, key=lambda x:sort_key(x.name)):
|
||||||
e.dump(prefix=prefix+' ', out=out)
|
e.dump(prefix=prefix+' ', out=out)
|
||||||
|
|
||||||
|
def list(self, recurse=False):
|
||||||
|
if not self.is_folder:
|
||||||
|
parent = self.id_map[self.parent_id]
|
||||||
|
yield '/'.join(parent.full_path[1:]), ListEntry(self)
|
||||||
|
return
|
||||||
|
entries = [ListEntry(x) for x in chain(self.folders, self.files)]
|
||||||
|
yield '/'.join(self.full_path[1:]), entries
|
||||||
|
if recurse:
|
||||||
|
for x in self.folders:
|
||||||
|
yield from x.list(recurse=True)
|
||||||
|
|
||||||
def folder_named(self, name):
|
def folder_named(self, name):
|
||||||
name = lower(name)
|
name = lower(name)
|
||||||
for e in self.folders:
|
for e in self.folders:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user