From 1a7dc8973d1c9e204a2591fe2b15db1134d6bd23 Mon Sep 17 00:00:00 2001 From: "Br. Samuel Springuel" Date: Tue, 26 Aug 2014 20:33:05 -0400 Subject: [PATCH] New option to indicate whether an existing apnx file on the kindle should be overwritten. This option makes explicit the existing behavior and allows for it to be turned off so that if a book being sent to the kindle already has an apnx file on the kindle, that apnx file is preserved instead of a new one being generated. --- src/calibre/devices/kindle/driver.py | 35 ++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 3e8fdac86f..fa2cd447fd 100644 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -323,16 +323,29 @@ class KINDLE2(KINDLE): ' store the page count of books, you can have calibre use that' ' information, instead of calculating a page count. Specify the' ' name of the custom column here, for example, #pages.'), + ### New option to indicate whether an existing apnx file on the kindle should be overwritten when sending to the device. + _('Overwrite existing apnx on device') + ':::' + _( + 'Uncheck this option to allow an apnx file existing on the device' + ' to have priority over the version which calibre would send.' + ' Since apnx files are usually deleted when a book is removed from' + ' the Kindle, this is mostly useful when resending a book to the' + ' device which is already on the device (e.g. after making a' + ' modification.)'), + ### ] EXTRA_CUSTOMIZATION_DEFAULT = [ True, 'fast', '', + True, ] OPT_APNX = 0 OPT_APNX_METHOD = 1 OPT_APNX_CUST_COL = 2 + ### New option + OPT_APNX_OVERWRITE = 3 + ### EXTRA_CUSTOMIZATION_CHOICES = {OPT_APNX_METHOD:{'fast', 'accurate', 'pagebreak'}} # x330 on the PaperWhite @@ -456,13 +469,21 @@ class KINDLE2(KINDLE): apnx_path = '%s.apnx' % os.path.join(path, filename) apnx_builder = APNXBuilder() - try: - method = opts.extra_customization[self.OPT_APNX_METHOD] - apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count) - except: - print 'Failed to generate APNX' - import traceback - traceback.print_exc() + ### Check to see if there is an existing apnx file on Kindle we should keep. + apnx_file = '%s.apnx' % os.path.splitext(filepath.lower())[0] + if not opts.extra_customization[self.OPT_APNX_OVERWRITE] and os.path.isfile(apnx_path): + pass #do nothing, existing apnx file on the kindle is kept + else: + ### This was existing code just dedented one level + try: + method = opts.extra_customization[self.OPT_APNX_METHOD] + apnx_builder.write_apnx(filepath, apnx_path, method=method, page_count=custom_page_count) + except: + print 'Failed to generate APNX' + import traceback + traceback.print_exc() + ### + ### class KINDLE_DX(KINDLE2):