Fix problem of invalid datetime metadata coming from a device.

1) Catch errors in the smart device driver
2) Return None in the json_codec if a date cannot be parsed.
This commit is contained in:
Charles Haley 2014-12-15 18:47:06 +01:00
parent 4f6ca8d7d2
commit f98e92ab74
2 changed files with 22 additions and 15 deletions

View File

@ -1308,6 +1308,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self._debug('getting book metadata. Done', i, 'of', count)
opcode, result = self._receive_from_client(print_debug_info=False)
if opcode == 'OK':
try:
if '_series_sort_' in result:
del result['_series_sort_']
book = self.json_codec.raw_to_book(result, SDBook, self.PREFIX)
@ -1320,6 +1321,9 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
book.set('_new_book_', True)
else:
self._set_known_metadata(book)
except:
self._debug('exception retrieving metadata for book', result.get('title', 'Unknown'))
traceback.print_exc()
else:
raise ControlError(desc='book metadata not returned')

View File

@ -17,9 +17,12 @@ from calibre import isbytestring
# UTC. The returned date is also UTC
def string_to_datetime(src):
from calibre.utils.date import parse_date
if src == "None":
return None
if src != "None":
try:
return parse_date(src)
except:
pass
return None
def datetime_to_string(dateval):
from calibre.utils.date import isoformat, UNDEFINED_DATE, local_tz