mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
a593a2ce7b
commit
23e87b0178
@ -82,6 +82,10 @@ class MTP_DEVICE(BASE):
|
|||||||
|
|
||||||
return self._prefs
|
return self._prefs
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_kindle(self) -> bool:
|
||||||
|
return self.current_vid == 0x1949
|
||||||
|
|
||||||
def is_folder_ignored(self, storage_or_storage_id, path,
|
def is_folder_ignored(self, storage_or_storage_id, path,
|
||||||
ignored_folders=None):
|
ignored_folders=None):
|
||||||
storage_id = str(getattr(storage_or_storage_id, 'object_id',
|
storage_id = str(getattr(storage_or_storage_id, 'object_id',
|
||||||
@ -92,7 +96,7 @@ class MTP_DEVICE(BASE):
|
|||||||
if storage_id in ignored_folders:
|
if storage_id in ignored_folders:
|
||||||
# Use the users ignored folders settings
|
# Use the users ignored folders settings
|
||||||
return '/'.join(lpath) in {icu_lower(x) for x in ignored_folders[storage_id]}
|
return '/'.join(lpath) in {icu_lower(x) for x in ignored_folders[storage_id]}
|
||||||
if self.current_vid == 0x1949 and lpath and lpath[-1].endswith('.sdr'):
|
if self.is_kindle and lpath and lpath[-1].endswith('.sdr'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Implement the default ignore policy
|
# Implement the default ignore policy
|
||||||
@ -106,7 +110,7 @@ class MTP_DEVICE(BASE):
|
|||||||
if lpath[0].startswith('.') and lpath[0] != '.tolino':
|
if lpath[0].startswith('.') and lpath[0] != '.tolino':
|
||||||
# apparently the Tolino for some reason uses a hidden folder for its library, sigh.
|
# apparently the Tolino for some reason uses a hidden folder for its library, sigh.
|
||||||
return True
|
return True
|
||||||
if lpath[0] == 'system' and self.current_vid != 0x1949:
|
if lpath[0] == 'system' and not self.is_kindle:
|
||||||
# on Kindles we need the system folder for the amazon cover bug workaround
|
# on Kindles we need the system folder for the amazon cover bug workaround
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -151,7 +155,7 @@ 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:
|
if self.is_kindle:
|
||||||
try:
|
try:
|
||||||
self.sync_kindle_thumbnails()
|
self.sync_kindle_thumbnails()
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -499,7 +503,7 @@ class MTP_DEVICE(BASE):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def upload_cover(self, parent_folder: FileOrFolder, relpath_of_ebook_on_device: Sequence[str], storage: FileOrFolder, mi, ebook_file_as_stream):
|
def upload_cover(self, parent_folder: FileOrFolder, relpath_of_ebook_on_device: Sequence[str], storage: FileOrFolder, mi, ebook_file_as_stream):
|
||||||
if self.current_vid == 0x1949:
|
if self.is_kindle:
|
||||||
self.upload_kindle_thumbnail(parent_folder, relpath_of_ebook_on_device, storage, mi, ebook_file_as_stream)
|
self.upload_kindle_thumbnail(parent_folder, relpath_of_ebook_on_device, storage, mi, ebook_file_as_stream)
|
||||||
|
|
||||||
# Kindle cover thumbnail handling {{{
|
# Kindle cover thumbnail handling {{{
|
||||||
@ -614,7 +618,7 @@ class MTP_DEVICE(BASE):
|
|||||||
fpath = f.mtp_relpath
|
fpath = f.mtp_relpath
|
||||||
storage = f.storage
|
storage = f.storage
|
||||||
self.recursive_delete(f)
|
self.recursive_delete(f)
|
||||||
if self.current_vid == 0x1949:
|
if self.is_kindle:
|
||||||
self.delete_kindle_cover_thumbnail_for(storage, fpath)
|
self.delete_kindle_cover_thumbnail_for(storage, fpath)
|
||||||
self.report_progress((i+1) / float(len(paths)),
|
self.report_progress((i+1) / float(len(paths)),
|
||||||
_('Deleted %s')%path)
|
_('Deleted %s')%path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user