From 540032080c59d2ae7bead1045f5f329265127d7e Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Wed, 16 Feb 2011 22:08:12 -0400 Subject: [PATCH] Fix bugs 8449, 8485, 8844, 8915 - Some fields in database include binary characters that cannot be intrepreted as Unicode --- src/calibre/devices/kobo/driver.py | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index c5e8f5ca0f..6ffd542a06 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -22,7 +22,7 @@ class KOBO(USBMS): gui_name = 'Kobo Reader' description = _('Communicate with the Kobo Reader') author = 'Timothy Legge and Kovid Goyal' - version = (1, 0, 7) + version = (1, 0, 9) dbversion = 0 fwversion = 0 @@ -125,9 +125,12 @@ class KOBO(USBMS): if imagename is not None: bl[idx].thumbnail = ImageWrapper(imagename) if (ContentType != '6' and MimeType != 'Shortcover'): - if self.update_metadata_item(bl[idx]): - # print 'update_metadata_item returned true' - changed = True + if os.path.exists(self.normalize_path(os.path.join(prefix, lpath))): + if self.update_metadata_item(bl[idx]): + # print 'update_metadata_item returned true' + changed = True + else: + debug_print(" Strange: The file: ", prefix, lpath, " does mot exist!") if lpath in playlist_map and \ playlist_map[lpath] not in bl[idx].device_collections: bl[idx].device_collections.append(playlist_map[lpath]) @@ -136,7 +139,13 @@ class KOBO(USBMS): book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=1048576) else: try: - book = self.book_from_path(prefix, lpath, title, authors, mime, date, ContentType, ImageID) + if os.path.exists(self.normalize_path(os.path.join(prefix, lpath))): + book = self.book_from_path(prefix, lpath, title, authors, mime, date, ContentType, ImageID) + else: + debug_print(" Strange: The file: ", prefix, lpath, " does mot exist!") + title = "FILE MISSING: " + title + book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=1048576) + except: debug_print("prefix: ", prefix, "lpath: ", lpath, "title: ", title, "authors: ", authors, \ "mime: ", mime, "date: ", date, "ContentType: ", ContentType, "ImageID: ", ImageID) @@ -153,6 +162,10 @@ class KOBO(USBMS): return changed connection = sqlite.connect(self.normalize_path(self._main_prefix + '.kobo/KoboReader.sqlite')) + + # return bytestrings if the content cannot the decoded as unicode + connection.text_factory = lambda x: unicode(x, "utf-8", "ignore") + cursor = connection.cursor() #query = 'select count(distinct volumeId) from volume_shortcovers' @@ -222,6 +235,10 @@ class KOBO(USBMS): debug_print('delete_via_sql: ContentID: ', ContentID, 'ContentType: ', ContentType) connection = sqlite.connect(self.normalize_path(self._main_prefix + '.kobo/KoboReader.sqlite')) + + # return bytestrings if the content cannot the decoded as unicode + connection.text_factory = lambda x: unicode(x, "utf-8", "ignore") + cursor = connection.cursor() t = (ContentID,) cursor.execute('select ImageID from content where ContentID = ?', t) @@ -495,6 +512,10 @@ class KOBO(USBMS): # the last book from the collection the list of books is empty # and the removal of the last book would not occur connection = sqlite.connect(self.normalize_path(self._main_prefix + '.kobo/KoboReader.sqlite')) + + # return bytestrings if the content cannot the decoded as unicode + connection.text_factory = lambda x: unicode(x, "utf-8", "ignore") + cursor = connection.cursor()