From 0714264e172993f3c2f26c5244af87f08d45dc9c Mon Sep 17 00:00:00 2001 From: Kolenka Date: Sun, 15 Apr 2012 23:27:41 -0700 Subject: [PATCH 1/7] Further Robustness for T1 Driver --- src/calibre/devices/prst1/driver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 12867e0859..c2b04f11f7 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -307,11 +307,21 @@ class PRST1(USBMS): # Work-around for Sony Bug (SD Card DB not using right SQLite sequence) if source_id == 1: + # Update any existing sequence numbers in the table that aren't in the required range sdcard_sequence_start = '4294967296' query = 'UPDATE sqlite_sequence SET seq = ? WHERE seq < ?' t = (sdcard_sequence_start, sdcard_sequence_start,) cursor.execute(query, t) + # Insert sequence numbers for tables we will be manipulating, if they don't already exist + query = ('INSERT INTO sqlite_sequence (name, seq) ' + 'SELECT ?, ? ' + 'WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = ?)'); + cursor.execute(query, ('books',sdcard_sequence_start,'books',)) + cursor.execute(query, ('collection',sdcard_sequence_start,'collection',)) + cursor.execute(query, ('collections',sdcard_sequence_start,'collections',)) + + for book in booklist: # Run through plugboard if needed if plugboard is not None: From dcbd96a7d17d0d8fe4cc5ccb3aa8aa747407ea33 Mon Sep 17 00:00:00 2001 From: Kolenka Date: Wed, 30 May 2012 22:37:24 -0700 Subject: [PATCH 2/7] Fixes for PRS-T1 Sony Bug. This one should actually provide some retroactive fixes, and better support for lastrowid. --- src/calibre/devices/prst1/driver.py | 185 +++++++++++++++++++++++----- 1 file changed, 152 insertions(+), 33 deletions(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index c2b04f11f7..44b2beb14f 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -273,17 +273,36 @@ class PRST1(USBMS): self.update_device_collections(connection, booklist, collections, source_id) debug_print('PRST1: finished update_device_database') + + def get_database_min_id(self, source_id): + sequence_min = 0 + if source_id == '1': + sequence_min = 4294967296 + + return sequence_min + + def set_database_sequence_id(self, connection, table, sequence_id): + cursor = connection.cursor() + + # Update the sequence Id if it exists + query = 'UPDATE sqlite_sequence SET seq = ? WHERE name = ?' + t = (sequence_id, table,) + cursor.execute(query, t) - def update_device_books(self, connection, booklist, source_id, plugboard, - dbpath): - from sqlite3 import DatabaseError - - opts = self.settings() - upload_covers = opts.extra_customization[self.OPT_UPLOAD_COVERS] - refresh_covers = opts.extra_customization[self.OPT_REFRESH_COVERS] - use_sony_authors = opts.extra_customization[self.OPT_USE_SONY_AUTHORS] - - try: + # Insert the sequence Id if it doesn't + query = ('INSERT INTO sqlite_sequence (name, seq) ' + 'SELECT ?, ? ' + 'WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = ?)'); + cursor.execute(query, (table, sequence_id, table,)) + + cursor.close() + + def read_device_books(self, connection, source_id): + sequence_min = self.get_database_min_id(source_id) + sequence_max = sequence_min + sequence_dirty = 0 + + try: cursor = connection.cursor() # Get existing books @@ -300,28 +319,53 @@ class PRST1(USBMS): ' any notes/highlights, etc.')%dbpath)+' Underlying error:' '\n'+tb) + # Get the books themselves, but keep track of any that are less than the minimum. + # Record what the max id being used is as well. db_books = {} for i, row in enumerate(cursor): lpath = row[0].replace('\\', '/') - db_books[lpath] = row[1] + db_books[lpath] = row[1] + if row[1] < sequence_min: + sequence_dirty = 1 + else: + sequence_max = max(sequence_max, row[1]) - # Work-around for Sony Bug (SD Card DB not using right SQLite sequence) - if source_id == 1: - # Update any existing sequence numbers in the table that aren't in the required range - sdcard_sequence_start = '4294967296' - query = 'UPDATE sqlite_sequence SET seq = ? WHERE seq < ?' - t = (sdcard_sequence_start, sdcard_sequence_start,) - cursor.execute(query, t) - - # Insert sequence numbers for tables we will be manipulating, if they don't already exist - query = ('INSERT INTO sqlite_sequence (name, seq) ' - 'SELECT ?, ? ' - 'WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = ?)'); - cursor.execute(query, ('books',sdcard_sequence_start,'books',)) - cursor.execute(query, ('collection',sdcard_sequence_start,'collection',)) - cursor.execute(query, ('collections',sdcard_sequence_start,'collections',)) + # If the database is 'dirty', then we should fix up the Ids and the sequence number + if sequence_dirty == 1: + sequence_max = sequence_max + 1 + for book, bookId in db_books.items(): + if bookId < sequence_min: + # Record the new Id and write it to the DB + db_books[book] = sequence_max + sequence_max = sequence_max + 1 + + # Fix the Books DB + query = 'UPDATE books SET _id = ? WHERE file_path = ?' + t = (db_books[book], book,) + cursor.execute(query, t) + + # Fix any references in existing collections + query = 'UPDATE collections SET content_id = ? WHERE content_id = ?' + t = (db_books[book], bookId,) + cursor.execute(query, t) + self.set_database_sequence_id(connection, 'books', sequence_max) + cursor.close() + return db_books + + def update_device_books(self, connection, booklist, source_id, plugboard, + dbpath): + from sqlite3 import DatabaseError + + opts = self.settings() + upload_covers = opts.extra_customization[self.OPT_UPLOAD_COVERS] + refresh_covers = opts.extra_customization[self.OPT_REFRESH_COVERS] + use_sony_authors = opts.extra_customization[self.OPT_USE_SONY_AUTHORS] + + db_books = self.read_device_books(connection, source_id) + cursor = connection.cursor() + for book in booklist: # Run through plugboard if needed if plugboard is not None: @@ -400,18 +444,93 @@ class PRST1(USBMS): connection.commit() cursor.close() + def read_device_collections(self, connection, source_id): + sequence_min = self.get_database_min_id(source_id) + sequence_max = sequence_min + sequence_dirty = 0 + + try: + cursor = connection.cursor() + + # Get existing collections + query = 'SELECT _id, title FROM collection' + cursor.execute(query) + except DatabaseError: + import traceback + tb = traceback.format_exc() + raise DeviceError((('The SONY database is corrupted. ' + ' Delete the file %s on your reader and then disconnect ' + ' reconnect it. If you are using an SD card, you ' + ' should delete the file on the card as well. Note that ' + ' deleting this file will cause your reader to forget ' + ' any notes/highlights, etc.')%dbpath)+' Underlying error:' + '\n'+tb) + + db_collections = {} + for i, row in enumerate(cursor): + db_collections[row[1]] = row[0] + if row[0] < sequence_min: + sequence_dirty = 1 + else: + sequence_max = max(sequence_max, row[0]) + + # If the database is 'dirty', then we should fix up the Ids and the sequence number + if sequence_dirty == 1: + sequence_max = sequence_max + 1 + for collection, collectionId in db_collections.items(): + if collectionId < sequence_min: + # Record the new Id and write it to the DB + db_collections[collection] = sequence_max + sequence_max = sequence_max + 1 + + # Fix the collection DB + query = 'UPDATE collection SET _id = ? WHERE title = ?' + t = (db_collections[collection], collection, ) + cursor.execute(query, t) + + # Fix any references in existing collections + query = 'UPDATE collections SET collection_id = ? WHERE collection_id = ?' + t = (db_collections[collection], collectionId,) + cursor.execute(query, t) + + self.set_database_sequence_id(connection, 'collection', sequence_max) + + # Fix up the collections table now... + sequence_dirty = 0 + sequence_max = sequence_min + + query = 'SELECT _id FROM collections' + cursor.execute(query) + + db_collection_pairs = [] + for i, row in enumerate(cursor): + db_collection_pairs.append(row[0]) + if row[0] < sequence_min: + sequence_dirty = 1 + else: + sequence_max = max(sequence_max, row[0]) + + if sequence_dirty == 1: + sequence_max = sequence_max + 1 + for pairId in db_collection_pairs: + if pairId < sequence_min: + # Record the new Id and write it to the DB + query = 'UPDATE collections SET _id = ? WHERE _id = ?' + t = (sequence_max, pairId,) + cursor.execute(query, t) + sequence_max = sequence_max + 1 + + self.set_database_sequence_id(connection, 'collection', sequence_max) + + cursor.close() + return db_collections + def update_device_collections(self, connection, booklist, collections, source_id): cursor = connection.cursor() if collections: - # Get existing collections - query = 'SELECT _id, title FROM collection' - cursor.execute(query) - - db_collections = {} - for i, row in enumerate(cursor): - db_collections[row[1]] = row[0] + db_collections = self.read_device_collections(connection, source_id) for collection, books in collections.items(): if collection not in db_collections: From 5b4a95d737cf49f3f120cba370a5f5c76d17f14f Mon Sep 17 00:00:00 2001 From: Kolenka Date: Wed, 30 May 2012 22:41:36 -0700 Subject: [PATCH 3/7] Whitespace Fixes --- src/calibre/devices/prst1/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 44b2beb14f..65b7e35dcd 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -363,7 +363,7 @@ class PRST1(USBMS): refresh_covers = opts.extra_customization[self.OPT_REFRESH_COVERS] use_sony_authors = opts.extra_customization[self.OPT_USE_SONY_AUTHORS] - db_books = self.read_device_books(connection, source_id) + db_books = self.read_device_books(connection, source_id) cursor = connection.cursor() for book in booklist: From 6cb7b2b5865e0f7d7c70aae64fe9846c30a8cdb9 Mon Sep 17 00:00:00 2001 From: Kolenka Date: Wed, 30 May 2012 22:53:37 -0700 Subject: [PATCH 4/7] Go whole hog on the retroactive repairs. --- src/calibre/devices/prst1/driver.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 65b7e35dcd..d2d6279695 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -275,7 +275,7 @@ class PRST1(USBMS): debug_print('PRST1: finished update_device_database') def get_database_min_id(self, source_id): - sequence_min = 0 + sequence_min = 700000000 if source_id == '1': sequence_min = 4294967296 @@ -344,9 +344,27 @@ class PRST1(USBMS): t = (db_books[book], book,) cursor.execute(query, t) - # Fix any references in existing collections - query = 'UPDATE collections SET content_id = ? WHERE content_id = ?' + # Fix any references so that they point back to the right book t = (db_books[book], bookId,) + query = 'UPDATE collections SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE annotation SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE bookmark SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE current_position SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE deleted_markups SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE dic_histories SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE freehand SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE history SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE layout_cache SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE preference SET content_id = ? WHERE content_id = ?' cursor.execute(query, t) self.set_database_sequence_id(connection, 'books', sequence_max) From 80b3b30578649c0719ae918a16ea8cf10c077fd9 Mon Sep 17 00:00:00 2001 From: Kolenka Date: Wed, 30 May 2012 22:54:57 -0700 Subject: [PATCH 5/7] Fix typo --- src/calibre/devices/prst1/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index d2d6279695..f9681c97cb 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -275,7 +275,7 @@ class PRST1(USBMS): debug_print('PRST1: finished update_device_database') def get_database_min_id(self, source_id): - sequence_min = 700000000 + sequence_min = 0 if source_id == '1': sequence_min = 4294967296 From 37884fe1734725629536188d4b3eb7a36d323b9e Mon Sep 17 00:00:00 2001 From: Kolenka Date: Sun, 3 Jun 2012 17:31:34 -0700 Subject: [PATCH 6/7] Fixes to T1 driver --- src/calibre/devices/prst1/driver.py | 264 ++++++++++++++-------------- 1 file changed, 132 insertions(+), 132 deletions(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index f9681c97cb..c761c93d44 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -275,34 +275,34 @@ class PRST1(USBMS): debug_print('PRST1: finished update_device_database') def get_database_min_id(self, source_id): - sequence_min = 0 - if source_id == '1': - sequence_min = 4294967296 - - return sequence_min - - def set_database_sequence_id(self, connection, table, sequence_id): - cursor = connection.cursor() - - # Update the sequence Id if it exists + sequence_min = 0L + if source_id == '1': + sequence_min = 4294967296L + + return sequence_min + + def set_database_sequence_id(self, connection, table, sequence_id): + cursor = connection.cursor() + + # Update the sequence Id if it exists query = 'UPDATE sqlite_sequence SET seq = ? WHERE name = ?' t = (sequence_id, table,) cursor.execute(query, t) - # Insert the sequence Id if it doesn't - query = ('INSERT INTO sqlite_sequence (name, seq) ' - 'SELECT ?, ? ' - 'WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = ?)'); - cursor.execute(query, (table, sequence_id, table,)) - - cursor.close() - + # Insert the sequence Id if it doesn't + query = ('INSERT INTO sqlite_sequence (name, seq) ' + 'SELECT ?, ? ' + 'WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = ?)'); + cursor.execute(query, (table, sequence_id, table,)) + + cursor.close() + def read_device_books(self, connection, source_id): - sequence_min = self.get_database_min_id(source_id) - sequence_max = sequence_min - sequence_dirty = 0 - - try: + sequence_min = self.get_database_min_id(source_id) + sequence_max = sequence_min + sequence_dirty = 0 + + try: cursor = connection.cursor() # Get existing books @@ -319,58 +319,58 @@ class PRST1(USBMS): ' any notes/highlights, etc.')%dbpath)+' Underlying error:' '\n'+tb) - # Get the books themselves, but keep track of any that are less than the minimum. - # Record what the max id being used is as well. + # Get the books themselves, but keep track of any that are less than the minimum. + # Record what the max id being used is as well. db_books = {} for i, row in enumerate(cursor): lpath = row[0].replace('\\', '/') - db_books[lpath] = row[1] - if row[1] < sequence_min: - sequence_dirty = 1 - else: + db_books[lpath] = row[1] + if row[1] < sequence_min: + sequence_dirty = 1 + else: sequence_max = max(sequence_max, row[1]) - # If the database is 'dirty', then we should fix up the Ids and the sequence number - if sequence_dirty == 1: - sequence_max = sequence_max + 1 - for book, bookId in db_books.items(): - if bookId < sequence_min: - # Record the new Id and write it to the DB - db_books[book] = sequence_max - sequence_max = sequence_max + 1 - - # Fix the Books DB - query = 'UPDATE books SET _id = ? WHERE file_path = ?' - t = (db_books[book], book,) - cursor.execute(query, t) - - # Fix any references so that they point back to the right book - t = (db_books[book], bookId,) - query = 'UPDATE collections SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE annotation SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE bookmark SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE current_position SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE deleted_markups SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE dic_histories SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE freehand SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE history SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE layout_cache SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - query = 'UPDATE preference SET content_id = ? WHERE content_id = ?' - cursor.execute(query, t) - - self.set_database_sequence_id(connection, 'books', sequence_max) + # If the database is 'dirty', then we should fix up the Ids and the sequence number + if sequence_dirty == 1: + sequence_max = sequence_max + 1 + for book, bookId in db_books.items(): + if bookId < sequence_min: + # Record the new Id and write it to the DB + db_books[book] = sequence_max + sequence_max = sequence_max + 1 + + # Fix the Books DB + query = 'UPDATE books SET _id = ? WHERE file_path = ?' + t = (db_books[book], book,) + cursor.execute(query, t) + + # Fix any references so that they point back to the right book + t = (db_books[book], bookId,) + query = 'UPDATE collections SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE annotation SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE bookmark SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE current_position SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE deleted_markups SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE dic_histories SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE freehand SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE history SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE layout_cache SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + query = 'UPDATE preference SET content_id = ? WHERE content_id = ?' + cursor.execute(query, t) + + self.set_database_sequence_id(connection, 'books', sequence_max) - cursor.close() - return db_books + cursor.close() + return db_books def update_device_books(self, connection, booklist, source_id, plugboard, dbpath): @@ -381,9 +381,9 @@ class PRST1(USBMS): refresh_covers = opts.extra_customization[self.OPT_REFRESH_COVERS] use_sony_authors = opts.extra_customization[self.OPT_USE_SONY_AUTHORS] - db_books = self.read_device_books(connection, source_id) - cursor = connection.cursor() - + db_books = self.read_device_books(connection, source_id) + cursor = connection.cursor() + for book in booklist: # Run through plugboard if needed if plugboard is not None: @@ -462,12 +462,12 @@ class PRST1(USBMS): connection.commit() cursor.close() - def read_device_collections(self, connection, source_id): - sequence_min = self.get_database_min_id(source_id) - sequence_max = sequence_min - sequence_dirty = 0 - - try: + def read_device_collections(self, connection, source_id): + sequence_min = self.get_database_min_id(source_id) + sequence_max = sequence_min + sequence_dirty = 0 + + try: cursor = connection.cursor() # Get existing collections @@ -487,68 +487,68 @@ class PRST1(USBMS): db_collections = {} for i, row in enumerate(cursor): db_collections[row[1]] = row[0] - if row[0] < sequence_min: - sequence_dirty = 1 - else: - sequence_max = max(sequence_max, row[0]) + if row[0] < sequence_min: + sequence_dirty = 1 + else: + sequence_max = max(sequence_max, row[0]) - # If the database is 'dirty', then we should fix up the Ids and the sequence number - if sequence_dirty == 1: - sequence_max = sequence_max + 1 - for collection, collectionId in db_collections.items(): - if collectionId < sequence_min: - # Record the new Id and write it to the DB - db_collections[collection] = sequence_max - sequence_max = sequence_max + 1 - - # Fix the collection DB - query = 'UPDATE collection SET _id = ? WHERE title = ?' - t = (db_collections[collection], collection, ) - cursor.execute(query, t) - - # Fix any references in existing collections - query = 'UPDATE collections SET collection_id = ? WHERE collection_id = ?' - t = (db_collections[collection], collectionId,) - cursor.execute(query, t) - - self.set_database_sequence_id(connection, 'collection', sequence_max) - - # Fix up the collections table now... - sequence_dirty = 0 - sequence_max = sequence_min - - query = 'SELECT _id FROM collections' - cursor.execute(query) - - db_collection_pairs = [] - for i, row in enumerate(cursor): - db_collection_pairs.append(row[0]) - if row[0] < sequence_min: - sequence_dirty = 1 - else: + # If the database is 'dirty', then we should fix up the Ids and the sequence number + if sequence_dirty == 1: + sequence_max = sequence_max + 1 + for collection, collectionId in db_collections.items(): + if collectionId < sequence_min: + # Record the new Id and write it to the DB + db_collections[collection] = sequence_max + sequence_max = sequence_max + 1 + + # Fix the collection DB + query = 'UPDATE collection SET _id = ? WHERE title = ?' + t = (db_collections[collection], collection, ) + cursor.execute(query, t) + + # Fix any references in existing collections + query = 'UPDATE collections SET collection_id = ? WHERE collection_id = ?' + t = (db_collections[collection], collectionId,) + cursor.execute(query, t) + + self.set_database_sequence_id(connection, 'collection', sequence_max) + + # Fix up the collections table now... + sequence_dirty = 0 + sequence_max = sequence_min + + query = 'SELECT _id FROM collections' + cursor.execute(query) + + db_collection_pairs = [] + for i, row in enumerate(cursor): + db_collection_pairs.append(row[0]) + if row[0] < sequence_min: + sequence_dirty = 1 + else: sequence_max = max(sequence_max, row[0]) - if sequence_dirty == 1: - sequence_max = sequence_max + 1 - for pairId in db_collection_pairs: - if pairId < sequence_min: - # Record the new Id and write it to the DB - query = 'UPDATE collections SET _id = ? WHERE _id = ?' - t = (sequence_max, pairId,) - cursor.execute(query, t) - sequence_max = sequence_max + 1 - - self.set_database_sequence_id(connection, 'collection', sequence_max) - - cursor.close() - return db_collections - + if sequence_dirty == 1: + sequence_max = sequence_max + 1 + for pairId in db_collection_pairs: + if pairId < sequence_min: + # Record the new Id and write it to the DB + query = 'UPDATE collections SET _id = ? WHERE _id = ?' + t = (sequence_max, pairId,) + cursor.execute(query, t) + sequence_max = sequence_max + 1 + + self.set_database_sequence_id(connection, 'collections', sequence_max) + + cursor.close() + return db_collections + def update_device_collections(self, connection, booklist, collections, source_id): cursor = connection.cursor() if collections: - db_collections = self.read_device_collections(connection, source_id) + db_collections = self.read_device_collections(connection, source_id) for collection, books in collections.items(): if collection not in db_collections: From daab3e698fe5d499af54dd6c1c283781f749ef27 Mon Sep 17 00:00:00 2001 From: Kolenka Date: Sun, 3 Jun 2012 17:42:37 -0700 Subject: [PATCH 7/7] Clean up. --- src/calibre/devices/prst1/driver.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 7576588e6a..7da2b0f92f 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -270,7 +270,7 @@ class PRST1(USBMS): with closing(sqlite.connect(dbpath)) as connection: self.update_device_books(connection, booklist, source_id, plugboard, dbpath) - self.update_device_collections(connection, booklist, collections, source_id) + self.update_device_collections(connection, booklist, collections, source_id, dbpath) debug_print('PRST1: finished update_device_database') @@ -297,7 +297,7 @@ class PRST1(USBMS): cursor.close() - def read_device_books(self, connection, source_id): + def read_device_books(self, connection, source_id, dbpath): from sqlite3 import DatabaseError sequence_min = self.get_database_min_id(source_id) @@ -376,14 +376,12 @@ class PRST1(USBMS): def update_device_books(self, connection, booklist, source_id, plugboard, dbpath): - from sqlite3 import DatabaseError - opts = self.settings() upload_covers = opts.extra_customization[self.OPT_UPLOAD_COVERS] refresh_covers = opts.extra_customization[self.OPT_REFRESH_COVERS] use_sony_authors = opts.extra_customization[self.OPT_USE_SONY_AUTHORS] - db_books = self.read_device_books(connection, source_id) + db_books = self.read_device_books(connection, source_id, dbpath) cursor = connection.cursor() for book in booklist: @@ -464,7 +462,7 @@ class PRST1(USBMS): connection.commit() cursor.close() - def read_device_collections(self, connection, source_id): + def read_device_collections(self, connection, source_id, dbpath): from sqlite3 import DatabaseError sequence_min = self.get_database_min_id(source_id) @@ -548,11 +546,11 @@ class PRST1(USBMS): return db_collections def update_device_collections(self, connection, booklist, collections, - source_id): + source_id, dbpath): cursor = connection.cursor() if collections: - db_collections = self.read_device_collections(connection, source_id) + db_collections = self.read_device_collections(connection, source_id, dbpath) for collection, books in collections.items(): if collection not in db_collections: