Fix #871886 (Sony T1: Driver Bugfixes)

This commit is contained in:
Kovid Goyal 2011-10-11 03:53:08 +05:30
commit 35c5b5b7c6

View File

@ -265,7 +265,7 @@ class PRST1(USBMS):
values (?,?,?,?,?,?,?,?,?,0,0) values (?,?,?,?,?,?,?,?,?,0,0)
''' '''
t = (title, author, source_id, int(time.time() * 1000), t = (title, author, source_id, int(time.time() * 1000),
calendar.timegm(book.datetime), lpath, int(calendar.timegm(book.datetime) * 1000), lpath,
os.path.basename(book.lpath), book.size, book.mime) os.path.basename(book.lpath), book.size, book.mime)
cursor.execute(query, t) cursor.execute(query, t)
book.bookId = cursor.lastrowid book.bookId = cursor.lastrowid
@ -278,7 +278,7 @@ class PRST1(USBMS):
SET title = ?, author = ?, modified_date = ?, file_size = ? SET title = ?, author = ?, modified_date = ?, file_size = ?
WHERE file_path = ? WHERE file_path = ?
''' '''
t = (title, author, calendar.timegm(book.datetime), book.size, t = (title, author, int(calendar.timegm(book.datetime) * 1000), book.size,
lpath) lpath)
cursor.execute(query, t) cursor.execute(query, t)
book.bookId = db_books[lpath] book.bookId = db_books[lpath]
@ -337,9 +337,9 @@ class PRST1(USBMS):
db_books[row[0]] = row[1] db_books[row[0]] = row[1]
for idx, book in enumerate(books): for idx, book in enumerate(books):
if collection not in book.device_collections:
book.device_collections.append(collection)
if db_books.get(book.lpath, None) is None: if db_books.get(book.lpath, None) is None:
if collection not in book.device_collections:
book.device_collections.append(collection)
query = ''' query = '''
INSERT INTO collections (collection_id, content_id, INSERT INTO collections (collection_id, content_id,
added_order) values (?,?,?) added_order) values (?,?,?)
@ -403,6 +403,38 @@ class PRST1(USBMS):
debug_print('PRS-T1: finished rebuild_collections') debug_print('PRS-T1: finished rebuild_collections')
def upload_cover(self, path, filename, metadata, filepath):
debug_print('PRS-T1: uploading cover')
if filepath.startswith(self._main_prefix):
prefix = self._main_prefix
source_id = 0
else:
prefix = self._card_a_prefix
source_id = 1
metadata.lpath = filepath.partition(prefix)[2]
dbpath = self.normalize_path(prefix + DBPATH)
debug_print("SQLite DB Path: " + dbpath)
with closing(sqlite.connect(dbpath)) as connection:
cursor = connection.cursor()
query = 'SELECT _id FROM books WHERE file_path = ?'
t = (metadata.lpath,)
cursor.execute(query, t)
for i, row in enumerate(cursor):
metadata.bookId = row[0]
cursor.close()
if metadata.bookId is not None:
debug_print('PRS-T1: refreshing cover for book being sent')
self.upload_book_cover(connection, metadata, source_id)
debug_print('PRS-T1: done uploading cover')
def upload_book_cover(self, connection, book, source_id): def upload_book_cover(self, connection, book, source_id):
debug_print('PRST1: Uploading/Refreshing Cover for ' + book.title) debug_print('PRST1: Uploading/Refreshing Cover for ' + book.title)
if not book.thumbnail and book.thumbnail[-1]: if not book.thumbnail and book.thumbnail[-1]:
@ -424,4 +456,5 @@ class PRST1(USBMS):
t = (thumbnail_path, book.bookId,) t = (thumbnail_path, book.bookId,)
cursor.execute(query, t) cursor.execute(query, t)
connection.commit()
cursor.close() cursor.close()