mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 01:14:36 +02:00
Update size when sending book to Kobo device.
Thiis is to prevent the book from being deleted by the device when it processes new books after the disconnect.
This commit is contained in:
parent
39aa2072cb
commit
3b466e69e6
1 changed files with 44 additions and 4 deletions
|
|
@ -1706,18 +1706,19 @@ def imagefilename_from_imageID(self, ImageID):
|
|||
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||
metadata=None):
|
||||
debug_print('KoboTouch:upload_books - %d books'%(len(files)))
|
||||
debug_print('KoboTouch:upload_books - files=', files)
|
||||
|
||||
result = super(KOBOTOUCH, self).upload_books(files, names, on_card, end_session, metadata)
|
||||
# debug_print('KoboTouch:upload_books - result=', result)
|
||||
|
||||
if self.dbversion >= 53:
|
||||
if self.dbversion >= 53 and prefs['manage_device_metadata'] == 'on_connect':
|
||||
import sqlite3 as sqlite
|
||||
try:
|
||||
with closing(sqlite.connect(self.normalize_path(self._main_prefix +
|
||||
'.kobo/KoboReader.sqlite'))) as connection:
|
||||
connection.text_factory = lambda x: unicode(x, "utf-8", "ignore")
|
||||
cursor = connection.cursor()
|
||||
query = "DELETE FROM content WHERE ContentID = ? AND Accessibility = 1 AND IsDownloaded = 'false'"
|
||||
cleanup_query = "DELETE FROM content WHERE ContentID = ? AND Accessibility = 1 AND IsDownloaded = 'false'"
|
||||
|
||||
for fname, cycle in result:
|
||||
show_debug = self.is_debugging_title(fname)
|
||||
|
|
@ -1726,9 +1727,11 @@ def upload_books(self, files, names, on_card=None, end_session=True,
|
|||
debug_print('KoboTouch:upload_books: fname=', fname)
|
||||
debug_print('KoboTouch:upload_books: contentID=', contentID)
|
||||
|
||||
t = (contentID,)
|
||||
cleanup_values = (contentID,)
|
||||
# debug_print('KoboTouch:upload_books: Delete record left if deleted on Touch')
|
||||
cursor.execute(query, t)
|
||||
cursor.execute(cleanup_query, cleanup_values)
|
||||
|
||||
self.set_filesize_in_device_database(connection, contentID, fname)
|
||||
|
||||
connection.commit()
|
||||
|
||||
|
|
@ -2183,6 +2186,43 @@ def remove_book_from_device_bookshelves(self, connection, book):
|
|||
connection.commit()
|
||||
cursor.close()
|
||||
|
||||
def set_filesize_in_device_database(self, connection, contentID, fpath):
|
||||
show_debug = self.is_debugging_title(fpath)
|
||||
if show_debug:
|
||||
debug_print('KoboTouch:set_filesize_in_device_database contentID="%s"'%contentID)
|
||||
|
||||
test_query = 'SELECT ___FileSize ' \
|
||||
'FROM content ' \
|
||||
'WHERE ContentID = ? ' \
|
||||
' AND ContentType = 6'
|
||||
test_values = (contentID, )
|
||||
|
||||
updatequery = 'UPDATE content ' \
|
||||
'SET ___FileSize = ? ' \
|
||||
'WHERE ContentId = ? ' \
|
||||
'AND ContentType = 6'
|
||||
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(test_query, test_values)
|
||||
result = cursor.fetchone()
|
||||
if result is None:
|
||||
if show_debug:
|
||||
debug_print(' Did not find a record - new book on device')
|
||||
elif os.path.exists(fpath):
|
||||
file_size = os.stat(self.normalize_path(fpath)).st_size
|
||||
if show_debug:
|
||||
debug_print(' Found a record - will update - ___FileSize=', result[0], ' file_size=', file_size)
|
||||
if file_size != int(result[0]):
|
||||
update_values = (file_size, contentID, )
|
||||
cursor.execute(updatequery, update_values)
|
||||
if show_debug:
|
||||
debug_print(' Size updated.')
|
||||
|
||||
connection.commit()
|
||||
cursor.close()
|
||||
|
||||
# debug_print("KoboTouch:set_filesize_in_device_database - end")
|
||||
|
||||
def delete_empty_bookshelves(self, connection):
|
||||
debug_print("KoboTouch:delete_empty_bookshelves - start")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue