Kindle driver: Ensure page counts are correctly sent to the device when connecting to Kindle 4/Touch. Fixes #910279 (Kindle 4 Page number file upload fix)

This commit is contained in:
Kovid Goyal 2011-12-31 11:18:22 +05:30
commit 34f263bda1
2 changed files with 23 additions and 7 deletions

View File

@ -285,10 +285,10 @@ class KINDLE(USBMS):
class KINDLE2(KINDLE): class KINDLE2(KINDLE):
name = 'Kindle 2/3/4/Touch Device Interface' 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'] 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] PRODUCT_ID = [0x0002, 0x0004]
BCD = [0x0100] BCD = [0x0100]
@ -347,6 +347,12 @@ class KINDLE2(KINDLE):
if h in path_map: if h in path_map:
book.device_collections = list(sorted(path_map[h])) 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): def upload_cover(self, path, filename, metadata, filepath):
''' '''
Hijacking this function to write the apnx file. 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'): if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc'):
return 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_path = '%s.apnx' % os.path.join(path, filename)
apnx_builder = APNXBuilder() apnx_builder = APNXBuilder()
try: try:

View File

@ -10,7 +10,7 @@ driver. It is intended to be subclassed with the relevant parts implemented
for a particular device. for a particular device.
''' '''
import os, re, time, json, uuid, functools import os, re, time, json, uuid, functools, shutil
from itertools import cycle from itertools import cycle
from calibre.constants import numeric_version from calibre.constants import numeric_version
@ -339,10 +339,13 @@ class USBMS(CLI, Device):
filepath = os.path.splitext(path)[0] filepath = os.path.splitext(path)[0]
for ext in self.DELETE_EXTS: for ext in self.DELETE_EXTS:
if os.path.exists(filepath + ext): for x in (filepath, path):
os.unlink(filepath + ext) x += ext
if os.path.exists(path + ext): if os.path.exists(x):
os.unlink(path + ext) if os.path.isdir(x):
shutil.rmtree(x, ignore_errors=True)
else:
os.unlink(x)
if self.SUPPORTS_SUB_DIRS: if self.SUPPORTS_SUB_DIRS:
try: try: