From 1b0ee1d655c427bd4a32879b4b2943ca9433db20 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Tue, 4 Mar 2014 09:55:55 +0100 Subject: [PATCH 1/2] Fix some wireless device sync bugs. --- .../devices/smart_device_app/driver.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 2bf368e3f7..faf10d13a6 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -1208,8 +1208,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): {'canStream':True, 'canScan':True, 'willUseCachedMetadata': self.client_can_use_metadata_cache, - 'supportsSync': (self.is_read_sync_col or - self.is_read_date_sync_col)}) + 'supportsSync': (bool(self.is_read_sync_col) or + bool(self.is_read_date_sync_col))}) bl = CollectionsBookList(None, self.PREFIX, self.settings) if opcode == 'OK': count = result['count'] @@ -1309,8 +1309,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self._call_client('SEND_BOOKLISTS', {'count': count, 'collections': coldict, 'willStreamMetadata': True, - 'supportsSync': (self.is_read_sync_col or - self.is_read_date_sync_col)}, + 'supportsSync': (bool(self.is_read_sync_col) or + bool(self.is_read_date_sync_col))}, wait_for_response=False) if count: @@ -1320,8 +1320,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): opcode, result = self._call_client( 'SEND_BOOK_METADATA', {'index': i, 'count': count, 'data': book, - 'supportsSync': (self.is_read_sync_col or - self.is_read_date_sync_col)}, + 'supportsSync': (bool(self.is_read_sync_col) or + bool(self.is_read_date_sync_col))}, print_debug_info=False, wait_for_response=False) @@ -1514,8 +1514,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): is_changed = book.get('_is_read_changed_', None); is_read = book.get('_is_read_', None) + # This returns UNDEFINED_DATE if the value is None is_read_date = parse_date(book.get('_last_read_date_', None)); + if is_read_date == UNDEFINED_DATE: + is_read_date = None + value_to_return = None if is_changed == 2: @@ -1524,8 +1528,9 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): # through to the normal sync situation below, otherwise the calibre # value wins. The orig_* values are set to None to force the normal # sync code to actually sync because the values are different - orig_is_read_date = UNDEFINED_DATE + orig_is_read_date = None orig_is_read = None + if is_read is None: calibre_val = db.new_api.field_for(self.is_read_sync_col, id_, default_value=None) @@ -1537,10 +1542,10 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): 'to', calibre_val) value_to_return = set() - if is_read_date == UNDEFINED_DATE: + if is_read_date is None: calibre_val = db.new_api.field_for(self.is_read_date_sync_col, id_, default_value=None) - if calibre_val != UNDEFINED_DATE: + if calibre_val is not None and calibre_val != UNDEFINED_DATE: book.set('_force_send_metadata_', True) self._debug('special update is_read_date', book.get('title', 'huh?'), 'to', calibre_val) @@ -1575,7 +1580,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): try: if is_read_date != orig_is_read_date: self._debug('standard update book is_read_date', book.get('title', 'huh?'), - 'to', is_read_date) + 'to', is_read_date, 'was', orig_is_read_date) if self.is_read_date_sync_col: changed_books |= db.new_api.set_field(self.is_read_date_sync_col, {id_: is_read_date}) From 98d0e98acb0c61260668aba00c551dc39468a4c1 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Tue, 4 Mar 2014 10:17:27 +0100 Subject: [PATCH 2/2] Eliminate possible problems when using UNDEFINED_DATE --- src/calibre/devices/smart_device_app/driver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index faf10d13a6..23748af774 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -1469,7 +1469,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): @synchronous('sync_lock') def synchronize_with_db(self, db, id_, book): - from calibre.utils.date import parse_date, UNDEFINED_DATE + from calibre.utils.date import parse_date, is_date_undefined def show_message(message): self._call_client("DISPLAY_MESSAGE", {'messageKind': self.MESSAGE_SHOW_TOAST, @@ -1517,7 +1517,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): # This returns UNDEFINED_DATE if the value is None is_read_date = parse_date(book.get('_last_read_date_', None)); - if is_read_date == UNDEFINED_DATE: + if is_date_undefined(is_read_date): is_read_date = None value_to_return = None @@ -1545,7 +1545,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): if is_read_date is None: calibre_val = db.new_api.field_for(self.is_read_date_sync_col, id_, default_value=None) - if calibre_val is not None and calibre_val != UNDEFINED_DATE: + if not is_date_undefined(calibre_val): book.set('_force_send_metadata_', True) self._debug('special update is_read_date', book.get('title', 'huh?'), 'to', calibre_val)