mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
ba570d42c5
@ -543,7 +543,72 @@ class KOBO(USBMS):
|
|||||||
paths[source_id] = os.path.join(prefix, *(path.split('/')))
|
paths[source_id] = os.path.join(prefix, *(path.split('/')))
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
|
def reset_readstatus(self, connection, oncard):
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
# Reset Im_Reading list in the database
|
||||||
|
if oncard == 'carda':
|
||||||
|
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ContentID like \'file:///mnt/sd/%\''
|
||||||
|
elif oncard != 'carda' and oncard != 'cardb':
|
||||||
|
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ContentID not like \'file:///mnt/sd/%\''
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute (query)
|
||||||
|
except:
|
||||||
|
debug_print(' Database Exception: Unable to reset ReadStatus list')
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
connection.commit()
|
||||||
|
debug_print(' Commit: Reset ReadStatus list')
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
def set_readstatus(self, connection, ContentID, ReadStatus):
|
||||||
|
cursor = connection.cursor()
|
||||||
|
t = (ContentID,)
|
||||||
|
cursor.execute('select DateLastRead from Content where BookID is Null and ContentID = ?', t)
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if result is None:
|
||||||
|
datelastread = '1970-01-01T00:00:00'
|
||||||
|
else:
|
||||||
|
datelastread = result[0] if result[0] is not None else '1970-01-01T00:00:00'
|
||||||
|
|
||||||
|
t = (ReadStatus,datelastread,ContentID,)
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute('update content set ReadStatus=?,FirstTimeReading=\'false\',DateLastRead=? where BookID is Null and ContentID = ?', t)
|
||||||
|
except:
|
||||||
|
debug_print(' Database Exception: Unable update ReadStatus')
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
connection.commit()
|
||||||
|
debug_print(' Commit: Setting ReadStatus List')
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
def reset_favouritesindex(self, connection, oncard):
|
||||||
|
# Reset FavouritesIndex list in the database
|
||||||
|
if oncard == 'carda':
|
||||||
|
query= 'update content set FavouritesIndex=-1 where BookID is Null and ContentID like \'file:///mnt/sd/%\''
|
||||||
|
elif oncard != 'carda' and oncard != 'cardb':
|
||||||
|
query= 'update content set FavouritesIndex=-1 where BookID is Null and ContentID not like \'file:///mnt/sd/%\''
|
||||||
|
|
||||||
|
cursor = connection.cursor()
|
||||||
|
try:
|
||||||
|
cursor.execute (query)
|
||||||
|
except:
|
||||||
|
debug_print('Database Exception: Unable to reset Shortlist list')
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
connection.commit()
|
||||||
|
debug_print(' Commit: Reset FavouritesIndex list')
|
||||||
|
|
||||||
def update_device_database_collections(self, booklists, collections_attributes, oncard):
|
def update_device_database_collections(self, booklists, collections_attributes, oncard):
|
||||||
|
# Define lists for the ReadStatus
|
||||||
|
readstatuslist = {
|
||||||
|
"Im_Reading":1,
|
||||||
|
"Read":2,
|
||||||
|
"Closed":3,
|
||||||
|
}
|
||||||
# debug_print('Starting update_device_database_collections', collections_attributes)
|
# debug_print('Starting update_device_database_collections', collections_attributes)
|
||||||
|
|
||||||
# Force collections_attributes to be 'tags' as no other is currently supported
|
# Force collections_attributes to be 'tags' as no other is currently supported
|
||||||
@ -562,149 +627,35 @@ class KOBO(USBMS):
|
|||||||
# return bytestrings if the content cannot the decoded as unicode
|
# return bytestrings if the content cannot the decoded as unicode
|
||||||
connection.text_factory = lambda x: unicode(x, "utf-8", "ignore")
|
connection.text_factory = lambda x: unicode(x, "utf-8", "ignore")
|
||||||
|
|
||||||
cursor = connection.cursor()
|
|
||||||
|
|
||||||
|
|
||||||
if collections:
|
if collections:
|
||||||
|
|
||||||
|
# Need to reset the collections outside the particular loops
|
||||||
|
# otherwise the last item will not be removed
|
||||||
|
self.reset_readstatus(connection, oncard)
|
||||||
|
self.reset_favouritesindex(connection, oncard)
|
||||||
|
|
||||||
# Process any collections that exist
|
# Process any collections that exist
|
||||||
for category, books in collections.items():
|
for category, books in collections.items():
|
||||||
# debug_print (category)
|
# This is used to reset the Im_Reading, Read and Closed list
|
||||||
if category == 'Im_Reading':
|
# in the ReadStatus column of the Content table
|
||||||
# Reset Im_Reading list in the database
|
if category in readstatuslist.keys():
|
||||||
if oncard == 'carda':
|
debug_print("Category: ", category, " id = ", readstatuslist.get(category))
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ReadStatus = 1 and ContentID like \'file:///mnt/sd/%\''
|
|
||||||
elif oncard != 'carda' and oncard != 'cardb':
|
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ReadStatus = 1 and ContentID not like \'file:///mnt/sd/%\''
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute (query)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable to reset Im_Reading list')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
# debug_print('Commit: Reset Im_Reading list')
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
for book in books:
|
for book in books:
|
||||||
# debug_print('Title:', book.title, 'lpath:', book.path)
|
debug_print(' Title:', book.title, 'category: ', category)
|
||||||
if 'Im_Reading' not in book.device_collections:
|
if category not in book.device_collections:
|
||||||
book.device_collections.append('Im_Reading')
|
book.device_collections.append(category)
|
||||||
|
|
||||||
extension = os.path.splitext(book.path)[1]
|
extension = os.path.splitext(book.path)[1]
|
||||||
ContentType = self.get_content_type_from_extension(extension) if extension != '' else self.get_content_type_from_path(book.path)
|
ContentType = self.get_content_type_from_extension(extension) if extension != '' else self.get_content_type_from_path(book.path)
|
||||||
|
|
||||||
ContentID = self.contentid_from_path(book.path, ContentType)
|
ContentID = self.contentid_from_path(book.path, ContentType)
|
||||||
|
self.set_readstatus(connection, ContentID, readstatuslist.get(category))
|
||||||
t = (ContentID,)
|
|
||||||
cursor.execute('select DateLastRead from Content where BookID is Null and ContentID = ?', t)
|
|
||||||
result = cursor.fetchone()
|
|
||||||
if result is None:
|
|
||||||
datelastread = '1970-01-01T00:00:00'
|
|
||||||
else:
|
|
||||||
datelastread = result[0] if result[0] is not None else '1970-01-01T00:00:00'
|
|
||||||
|
|
||||||
t = (datelastread,ContentID,)
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute('update content set ReadStatus=1,FirstTimeReading=\'false\',DateLastRead=? where BookID is Null and ContentID = ?', t)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable create Im_Reading list')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
connection.commit()
|
|
||||||
# debug_print('Database: Commit create Im_Reading list')
|
|
||||||
if category == 'Read':
|
|
||||||
# Reset Im_Reading list in the database
|
|
||||||
if oncard == 'carda':
|
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ReadStatus = 2 and ContentID like \'file:///mnt/sd/%\''
|
|
||||||
elif oncard != 'carda' and oncard != 'cardb':
|
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ReadStatus = 2 and ContentID not like \'file:///mnt/sd/%\''
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute (query)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable to reset Im_Reading list')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
# debug_print('Commit: Reset Im_Reading list')
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
for book in books:
|
|
||||||
# debug_print('Title:', book.title, 'lpath:', book.path)
|
|
||||||
if 'Read' not in book.device_collections:
|
|
||||||
book.device_collections.append('Read')
|
|
||||||
|
|
||||||
extension = os.path.splitext(book.path)[1]
|
|
||||||
ContentType = self.get_content_type_from_extension(extension) if extension != '' else self.get_content_type_from_path(book.path)
|
|
||||||
|
|
||||||
ContentID = self.contentid_from_path(book.path, ContentType)
|
|
||||||
# datelastread = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
|
|
||||||
|
|
||||||
t = (ContentID,)
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute('update content set ReadStatus=2,FirstTimeReading=\'true\' where BookID is Null and ContentID = ?', t)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable set book as Finished')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
connection.commit()
|
|
||||||
# debug_print('Database: Commit set ReadStatus as Finished')
|
|
||||||
if category == 'Closed':
|
|
||||||
# Reset Im_Reading list in the database
|
|
||||||
if oncard == 'carda':
|
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ReadStatus = 3 and ContentID like \'file:///mnt/sd/%\''
|
|
||||||
elif oncard != 'carda' and oncard != 'cardb':
|
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ReadStatus = 3 and ContentID not like \'file:///mnt/sd/%\''
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute (query)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable to reset Closed list')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
# debug_print('Commit: Reset Closed list')
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
for book in books:
|
|
||||||
# debug_print('Title:', book.title, 'lpath:', book.path)
|
|
||||||
if 'Closed' not in book.device_collections:
|
|
||||||
book.device_collections.append('Closed')
|
|
||||||
|
|
||||||
extension = os.path.splitext(book.path)[1]
|
|
||||||
ContentType = self.get_content_type_from_extension(extension) if extension != '' else self.get_content_type_from_path(book.path)
|
|
||||||
|
|
||||||
ContentID = self.contentid_from_path(book.path, ContentType)
|
|
||||||
# datelastread = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
|
|
||||||
|
|
||||||
t = (ContentID,)
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute('update content set ReadStatus=3,FirstTimeReading=\'true\' where BookID is Null and ContentID = ?', t)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable set book as Closed')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
connection.commit()
|
|
||||||
# debug_print('Database: Commit set ReadStatus as Closed')
|
|
||||||
if category == 'Shortlist':
|
if category == 'Shortlist':
|
||||||
# Reset FavouritesIndex list in the database
|
debug_print("Category: ", category)
|
||||||
if oncard == 'carda':
|
cursor = connection.cursor()
|
||||||
query= 'update content set FavouritesIndex=-1 where BookID is Null and ContentID like \'file:///mnt/sd/%\''
|
|
||||||
elif oncard != 'carda' and oncard != 'cardb':
|
|
||||||
query= 'update content set FavouritesIndex=-1 where BookID is Null and ContentID not like \'file:///mnt/sd/%\''
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute (query)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable to reset Shortlist list')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
# debug_print('Commit: Reset Shortlist list')
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
for book in books:
|
for book in books:
|
||||||
# debug_print('Title:', book.title, 'lpath:', book.path)
|
debug_print(' Title:', book.title, 'category: ', category)
|
||||||
if 'Shortlist' not in book.device_collections:
|
if 'Shortlist' not in book.device_collections:
|
||||||
book.device_collections.append('Shortlist')
|
book.device_collections.append('Shortlist')
|
||||||
# debug_print ("Shortlist found for: ", book.title)
|
# debug_print ("Shortlist found for: ", book.title)
|
||||||
@ -727,23 +678,11 @@ class KOBO(USBMS):
|
|||||||
|
|
||||||
else: # No collections
|
else: # No collections
|
||||||
# Since no collections exist the ReadStatus needs to be reset to 0 (Unread)
|
# Since no collections exist the ReadStatus needs to be reset to 0 (Unread)
|
||||||
print "Reseting ReadStatus to 0"
|
debug_print("No Collections - reseting ReadStatus to 0")
|
||||||
# Reset Im_Reading list in the database
|
self.reset_readstatus(connection, oncard)
|
||||||
if oncard == 'carda':
|
debug_print("No Collections - reseting FavouritesIndex")
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ContentID like \'file:///mnt/sd/%\''
|
self.reset_favouritesindex(connection, oncard)
|
||||||
elif oncard != 'carda' and oncard != 'cardb':
|
|
||||||
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ContentID not like \'file:///mnt/sd/%\''
|
|
||||||
|
|
||||||
try:
|
|
||||||
cursor.execute (query)
|
|
||||||
except:
|
|
||||||
debug_print('Database Exception: Unable to reset Im_Reading list')
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
# debug_print('Commit: Reset Im_Reading list')
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
# debug_print('Finished update_device_database_collections', collections_attributes)
|
# debug_print('Finished update_device_database_collections', collections_attributes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user