diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 6e8bf8b8fb..935e9a4949 100644 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -285,10 +285,10 @@ class KINDLE(USBMS): class KINDLE2(KINDLE): name = 'Kindle 2/3/4/Touch Device Interface' - description = _('Communicate with the Kindle 2/3 eBook reader.') + description = _('Communicate with the Kindle 2/3/4/Touch eBook reader.') FORMATS = KINDLE.FORMATS + ['pdf', 'azw4', 'pobi'] - DELETE_EXTS = KINDLE.DELETE_EXTS + ['.mbp1', '.mbs'] + DELETE_EXTS = KINDLE.DELETE_EXTS + ['.mbp1', '.mbs', '.sdr'] PRODUCT_ID = [0x0002, 0x0004] BCD = [0x0100] @@ -347,6 +347,12 @@ class KINDLE2(KINDLE): if h in path_map: book.device_collections = list(sorted(path_map[h])) + # Detect if the product family needs .apnx files uploaded to sidecar folder + def post_open_callback(self): + product_id = self.device_being_opened[1] + # 4 for for Kindle 4 and 6 for Kindle Fire + self.sidecar_apnx = product_id in {0x4, 0x6} + def upload_cover(self, path, filename, metadata, filepath): ''' Hijacking this function to write the apnx file. @@ -358,6 +364,13 @@ class KINDLE2(KINDLE): if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc'): return + # Create the sidecar folder if necessary + if (self.sidecar_apnx): + path = os.path.join(os.path.dirname(filepath), filename+".sdr") + + if not os.path.exists(path): + os.makedirs(path) + apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() try: diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index ff2b6f3891..70b30e98a6 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -10,7 +10,7 @@ driver. It is intended to be subclassed with the relevant parts implemented for a particular device. ''' -import os, re, time, json, uuid, functools +import os, re, time, json, uuid, functools, shutil from itertools import cycle from calibre.constants import numeric_version @@ -339,10 +339,13 @@ class USBMS(CLI, Device): filepath = os.path.splitext(path)[0] for ext in self.DELETE_EXTS: - if os.path.exists(filepath + ext): - os.unlink(filepath + ext) - if os.path.exists(path + ext): - os.unlink(path + ext) + for x in (filepath, path): + x += ext + if os.path.exists(x): + if os.path.isdir(x): + shutil.rmtree(x, ignore_errors=True) + else: + os.unlink(x) if self.SUPPORTS_SUB_DIRS: try: