diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py
index ec00ca8d57..907a8b309a 100644
--- a/src/calibre/devices/kobo/driver.py
+++ b/src/calibre/devices/kobo/driver.py
@@ -75,8 +75,8 @@ class KOBO(USBMS):
VIRTUAL_BOOK_EXTENSIONS = frozenset(['kobo', ''])
EXTRA_CUSTOMIZATION_MESSAGE = [
- _('The Kobo supports several collections including ')+\
- 'Read, Closed, Im_Reading. ' +\
+ _('The Kobo supports several collections including ')+
+ 'Read, Closed, Im_Reading. ' +
_('Create tags for automatic management'),
_('Upload covers for books (newer readers)') +
':::'+_('Normally, the KOBO readers get the cover image from the'
@@ -220,7 +220,7 @@ class KOBO(USBMS):
# Try the Touch version if the image does not exist
imagename = self.normalize_path(self._main_prefix + '.kobo/images/' + ImageID + ' - N3_LIBRARY_FULL.parsed')
- #print "Image name Normalized: " + imagename
+ # print "Image name Normalized: " + imagename
if not os.path.exists(imagename):
debug_print("Strange - The image name does not exist - title: ", title)
if imagename is not None:
@@ -248,16 +248,16 @@ class KOBO(USBMS):
book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=1048576)
except:
- debug_print("prefix: ", prefix, "lpath: ", lpath, "title: ", title, "authors: ", authors, \
+ debug_print("prefix: ", prefix, "lpath: ", lpath, "title: ", title, "authors: ", authors,
"mime: ", mime, "date: ", date, "ContentType: ", ContentType, "ImageID: ", ImageID)
raise
# print 'Update booklist'
- book.device_collections = playlist_map.get(lpath,[])# if lpath in playlist_map else []
+ book.device_collections = playlist_map.get(lpath,[]) # if lpath in playlist_map else []
if bl.add_book(book, replace_metadata=False):
changed = True
- except: # Probably a path encoding error
+ except: # Probably a path encoding error
import traceback
traceback.print_exc()
return changed
@@ -280,35 +280,35 @@ class KOBO(USBMS):
opts = self.settings()
if self.dbversion >= 33:
- query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
- 'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, Accessibility, IsDownloaded from content where ' \
- 'BookID is Null %(previews)s %(recomendations)s and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)' \
- if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')', \
- previews=' and Accessibility <> 6' \
- if opts.extra_customization[self.OPT_SHOW_PREVIEWS] == False else '', \
- recomendations=' and IsDownloaded in (\'true\', 1)' \
+ query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
+ 'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, Accessibility, IsDownloaded from content where '
+ 'BookID is Null %(previews)s %(recomendations)s and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)'
+ if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')',
+ previews=' and Accessibility <> 6'
+ if opts.extra_customization[self.OPT_SHOW_PREVIEWS] == False else '',
+ recomendations=' and IsDownloaded in (\'true\', 1)'
if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] == False else '')
elif self.dbversion >= 16 and self.dbversion < 33:
- query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
- 'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, Accessibility, "1" as IsDownloaded from content where ' \
- 'BookID is Null and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)' \
+ query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
+ 'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, Accessibility, "1" as IsDownloaded from content where '
+ 'BookID is Null and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)'
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')')
elif self.dbversion < 16 and self.dbversion >= 14:
- query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
- 'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where ' \
- 'BookID is Null and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)' \
+ query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
+ 'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where '
+ 'BookID is Null and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)'
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')')
elif self.dbversion < 14 and self.dbversion >= 8:
- query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
- 'ImageID, ReadStatus, ___ExpirationStatus, "-1" as FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where ' \
- 'BookID is Null and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)' \
+ query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
+ 'ImageID, ReadStatus, ___ExpirationStatus, "-1" as FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where '
+ 'BookID is Null and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s') % dict(expiry=' and ContentType = 6)'
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')')
else:
query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
'ImageID, ReadStatus, "-1" as ___ExpirationStatus, "-1" as FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where BookID is Null'
try:
- cursor.execute (query)
+ cursor.execute(query)
except Exception as e:
err = str(e)
if not ('___ExpirationStatus' in err or 'FavouritesIndex' in err or
@@ -349,9 +349,9 @@ class KOBO(USBMS):
need_sync = True
del bl[idx]
- #print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
+ # print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
# (len(bl_cache), len(bl), need_sync)
- if need_sync: #self.count_found_in_bl != len(bl) or need_sync:
+ if need_sync: # self.count_found_in_bl != len(bl) or need_sync:
if oncard == 'cardb':
self.sync_booklists((None, None, bl))
elif oncard == 'carda':
@@ -391,7 +391,7 @@ class KOBO(USBMS):
# Delete the shortcover_pages first
cursor.execute('delete from shortcover_page where shortcoverid in (select ContentID from content where BookID = ?)', t)
- #Delete the volume_shortcovers second
+ # Delete the volume_shortcovers second
cursor.execute('delete from volume_shortcovers where volumeid = ?', t)
# Delete the rows from content_keys
@@ -405,18 +405,18 @@ class KOBO(USBMS):
cursor.execute('delete from content where BookID = ?', t)
if ContentType == 6:
try:
- cursor.execute('update content set ReadStatus=0, FirstTimeReading = \'true\', ___PercentRead=0, ___ExpirationStatus=3 ' \
+ cursor.execute('update content set ReadStatus=0, FirstTimeReading = \'true\', ___PercentRead=0, ___ExpirationStatus=3 '
'where BookID is Null and ContentID =?',t)
except Exception as e:
if 'no such column' not in str(e):
raise
try:
- cursor.execute('update content set ReadStatus=0, FirstTimeReading = \'true\', ___PercentRead=0 ' \
+ cursor.execute('update content set ReadStatus=0, FirstTimeReading = \'true\', ___PercentRead=0 '
'where BookID is Null and ContentID =?',t)
except Exception as e:
if 'no such column' not in str(e):
raise
- cursor.execute('update content set ReadStatus=0, FirstTimeReading = \'true\' ' \
+ cursor.execute('update content set ReadStatus=0, FirstTimeReading = \'true\' '
'where BookID is Null and ContentID =?',t)
else:
cursor.execute('delete from content where BookID is Null and ContentID =?',t)
@@ -436,7 +436,8 @@ class KOBO(USBMS):
path_prefix = '.kobo/images/'
path = self._main_prefix + path_prefix + ImageID
- file_endings = (' - iPhoneThumbnail.parsed', ' - bbMediumGridList.parsed', ' - NickelBookCover.parsed', ' - N3_LIBRARY_FULL.parsed', ' - N3_LIBRARY_GRID.parsed', ' - N3_LIBRARY_LIST.parsed', ' - N3_SOCIAL_CURRENTREAD.parsed', ' - N3_FULL.parsed',)
+ file_endings = (' - iPhoneThumbnail.parsed', ' - bbMediumGridList.parsed', ' - NickelBookCover.parsed', ' - N3_LIBRARY_FULL.parsed',
+ ' - N3_LIBRARY_GRID.parsed', ' - N3_LIBRARY_LIST.parsed', ' - N3_SOCIAL_CURRENTREAD.parsed', ' - N3_FULL.parsed',)
for ending in file_endings:
fpath = path + ending
@@ -460,7 +461,7 @@ class KOBO(USBMS):
ContentID = self.contentid_from_path(path, ContentType)
ImageID = self.delete_via_sql(ContentID, ContentType)
- #print " We would now delete the Images for" + ImageID
+ # print " We would now delete the Images for" + ImageID
self.delete_images(ImageID, path)
if os.path.exists(path):
@@ -493,9 +494,9 @@ class KOBO(USBMS):
self.report_progress((i+1) / float(len(paths)), _('Removing books from device metadata listing...'))
for bl in booklists:
for book in bl:
- #print "Book Path: " + book.path
+ # print "Book Path: " + book.path
if path.endswith(book.path):
- #print " Remove: " + book.path
+ # print " Remove: " + book.path
bl.remove_book(book)
self.report_progress(1.0, _('Removing books from device metadata listing...'))
@@ -524,12 +525,12 @@ class KOBO(USBMS):
prints('in add_books_to_metadata. Prefix is None!', path,
self._main_prefix)
continue
- #print "Add book to metatdata: "
- #print "prefix: " + prefix
+ # print "Add book to metatdata: "
+ # print "prefix: " + prefix
lpath = path.partition(prefix)[2]
if lpath.startswith('/') or lpath.startswith('\\'):
lpath = lpath[1:]
- #print "path: " + lpath
+ # print "path: " + lpath
book = self.book_class(prefix, lpath, other=info)
if book.size is None or book.size == 0:
book.size = os.stat(self.normalize_path(path)).st_size
@@ -551,12 +552,12 @@ class KOBO(USBMS):
if self._card_a_prefix is not None:
ContentID = ContentID.replace(self._card_a_prefix, '')
- elif ContentType == 999: # HTML Files
+ elif ContentType == 999: # HTML Files
ContentID = path
ContentID = ContentID.replace(self._main_prefix, "/mnt/onboard/")
if self._card_a_prefix is not None:
ContentID = ContentID.replace(self._card_a_prefix, "/mnt/sd/")
- else: # ContentType = 16
+ else: # ContentType = 16
ContentID = path
ContentID = ContentID.replace(self._main_prefix, "file:///mnt/onboard/")
if self._card_a_prefix is not None:
@@ -574,7 +575,7 @@ class KOBO(USBMS):
def get_content_type_from_extension(self, extension):
if extension == '.kobo':
# Kobo books do not have book files. They do have some images though
- #print "kobo book"
+ # print "kobo book"
ContentType = 6
elif extension == '.pdf' or extension == '.epub':
# print "ePub or pdf"
@@ -585,8 +586,8 @@ class KOBO(USBMS):
ContentType = 999
else:
ContentType = 901
- else: # if extension == '.html' or extension == '.txt':
- ContentType = 901 # Yet another hack: to get around Kobo changing how ContentID is stored
+ else: # if extension == '.html' or extension == '.txt':
+ ContentType = 901 # Yet another hack: to get around Kobo changing how ContentID is stored
return ContentType
def path_from_contentid(self, ContentID, ContentType, MimeType, oncard):
@@ -706,7 +707,7 @@ class KOBO(USBMS):
query= 'update content set ReadStatus=0, FirstTimeReading = \'true\' where BookID is Null and ContentID not like \'file:///mnt/sd/%\''
try:
- cursor.execute (query)
+ cursor.execute(query)
except:
debug_print(' Database Exception: Unable to reset ReadStatus list')
raise
@@ -747,7 +748,7 @@ class KOBO(USBMS):
cursor = connection.cursor()
try:
- cursor.execute (query)
+ cursor.execute(query)
except Exception as e:
debug_print(' Database Exception: Unable to reset Shortlist list')
if 'no such column' not in str(e):
@@ -847,7 +848,7 @@ class KOBO(USBMS):
elif category in accessibilitylist.keys():
# Do not manage the Accessibility List
pass
- else: # No collections
+ else: # No collections
# Since no collections exist the ReadStatus needs to be reset to 0 (Unread)
debug_print("No Collections - reseting ReadStatus")
self.reset_readstatus(connection, oncard)
@@ -857,7 +858,6 @@ class KOBO(USBMS):
# debug_print('Finished update_device_database_collections', collections_attributes)
-
def get_collections_attributes(self):
collections = []
opts = self.settings()
@@ -1107,15 +1107,15 @@ class KOBO(USBMS):
spanTag['style'] = 'font-weight:normal'
if bookmark.book_format == 'epub':
spanTag.insert(0,NavigableString(
- _("
Book Last Read: %(time)s
Percentage Read: %(pr)d%%
") % \
+ _("
Book Last Read: %(time)s
Percentage Read: %(pr)d%%
") %
dict(time=last_read,
- #loc=last_read_location,
+ # loc=last_read_location,
pr=percent_read)))
else:
spanTag.insert(0,NavigableString(
- _("
Book Last Read: %(time)s
Percentage Read: %(pr)d%%
") % \
+ _("
Book Last Read: %(time)s
Percentage Read: %(pr)d%%
") %
dict(time=last_read,
- #loc=last_read_location,
+ # loc=last_read_location,
pr=percent_read)))
divTag.insert(dtc, spanTag)
@@ -1131,7 +1131,7 @@ class KOBO(USBMS):
for location in sorted(user_notes):
if user_notes[location]['type'] == 'Bookmark':
annotations.append(
- _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
%(annotation)s
') % \
+ _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
%(annotation)s
') %
dict(chapter=user_notes[location]['chapter'],
dl=user_notes[location]['displayed_location'],
typ=user_notes[location]['type'],
@@ -1140,7 +1140,7 @@ class KOBO(USBMS):
annotation=user_notes[location]['annotation'] if user_notes[location]['annotation'] is not None else ""))
elif user_notes[location]['type'] == 'Highlight':
annotations.append(
- _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
Highlight: %(text)s
') % \
+ _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
Highlight: %(text)s
') %
dict(chapter=user_notes[location]['chapter'],
dl=user_notes[location]['displayed_location'],
typ=user_notes[location]['type'],
@@ -1149,7 +1149,7 @@ class KOBO(USBMS):
text=user_notes[location]['text']))
elif user_notes[location]['type'] == 'Annotation':
annotations.append(
- _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
Highlight: %(text)s
Notes: %(annotation)s
') % \
+ _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
Highlight: %(text)s
Notes: %(annotation)s
') %
dict(chapter=user_notes[location]['chapter'],
dl=user_notes[location]['displayed_location'],
typ=user_notes[location]['type'],
@@ -1159,13 +1159,13 @@ class KOBO(USBMS):
annotation=user_notes[location]['annotation']))
else:
annotations.append(
- _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
Highlight: %(text)s
Notes: %(annotation)s
') % \
+ _('Chapter %(chapter)d: %(chapter_title)s
%(typ)s
Chapter Progress: %(chapter_progress)s%%
Highlight: %(text)s
Notes: %(annotation)s
') %
dict(chapter=user_notes[location]['chapter'],
dl=user_notes[location]['displayed_location'],
typ=user_notes[location]['type'],
chapter_title=user_notes[location]['chapter_title'],
chapter_progress=user_notes[location]['chapter_progress'],
- text=user_notes[location]['text'], \
+ text=user_notes[location]['text'],
annotation=user_notes[location]['annotation']))
for annotation in annotations:
@@ -1240,8 +1240,8 @@ class KOBOTOUCH(KOBO):
KOBO_EXTRA_CSSFILE = 'kobo_extra.css'
EXTRA_CUSTOMIZATION_MESSAGE = [
- _('The Kobo Touch from firmware V2.0.0 supports bookshelves.')+\
- 'These are created on the Kobo Touch. ' +\
+ _('The Kobo Touch from firmware V2.0.0 supports bookshelves.')+
+ 'These are created on the Kobo Touch. ' +
_('Specify a tags type column for automatic management'),
_('Create Bookshelves') +
':::'+_('Create new bookshelves on the Kobo Touch if they do not exist. This is only for firmware V2.0.0 or later.'),
@@ -1346,20 +1346,19 @@ class KOBOTOUCH(KOBO):
}
AURA_HD_COVER_FILE_ENDINGS = {
' - N3_FULL.parsed': [(1080,1440), 0, 99,True,], # Used for screensaver, home screen
- ' - N3_LIBRARY_FULL.parsed':[(355, 471), 0, 99,False,], # Used for Details screen
- ' - N3_LIBRARY_GRID.parsed':[(149, 198), 0, 99,False,], # Used for library lists
+ ' - N3_LIBRARY_FULL.parsed':[(355, 471), 0, 99,False,], # Used for Details screen
+ ' - N3_LIBRARY_GRID.parsed':[(149, 198), 0, 99,False,], # Used for library lists
}
- #Following are the sizes used with pre2.1.4 firmware
+ # Following are the sizes used with pre2.1.4 firmware
# COVER_FILE_ENDINGS = {
-# ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], # Used for Details screen
-## ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,],
-# ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], # Used for library lists
+# ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], # Used for Details screen
+# ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,],
+# ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], # Used for library lists
# ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,],
# ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,],
-# ' - N3_FULL.parsed':[(600,800),0, 99,], # Used for screensaver if "Full screen" is checked.
+# ' - N3_FULL.parsed':[(600,800),0, 99,], # Used for screensaver if "Full screen" is checked.
# }
-
def initialize(self):
super(KOBOTOUCH, self).initialize()
self.bookshelvelist = []
@@ -1368,7 +1367,6 @@ class KOBOTOUCH(KOBO):
self.set_device_name()
return super(KOBOTOUCH, self).get_device_information(end_session)
-
def books(self, oncard=None, end_session=True):
debug_print("KoboTouch:books - oncard='%s'"%oncard)
from calibre.ebooks.metadata.meta import path_to_ext
@@ -1415,7 +1413,7 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:books - prefs['manage_device_metadata']=", prefs['manage_device_metadata'])
if opts.extra_customization:
debugging_title = opts.extra_customization[self.OPT_DEBUGGING_TITLE]
- debug_print("KoboTouch:books - set_debugging_title to '%s'" % debugging_title )
+ debug_print("KoboTouch:books - set_debugging_title to '%s'" % debugging_title)
bl.set_debugging_title(debugging_title)
debug_print("KoboTouch:books - length bl=%d"%len(bl))
need_sync = self.parse_metadata_cache(bl, prefix, self.METADATA_CACHE)
@@ -1431,7 +1429,8 @@ class KOBOTOUCH(KOBO):
# show_debug = authors == 'L. Frank Baum'
if show_debug:
debug_print("KoboTouch:update_booklist - title='%s'"%title, "ContentType=%s"%ContentType, "isdownloaded=", isdownloaded)
- debug_print(" prefix=%s, mime=%s, date=%s, readstatus=%d, MimeType=%s, expired=%d, favouritesindex=%d, accessibility=%d, isdownloaded=%s"%
+ debug_print(
+ " prefix=%s, mime=%s, date=%s, readstatus=%d, MimeType=%s, expired=%d, favouritesindex=%d, accessibility=%d, isdownloaded=%s"%
(prefix, mime, date, readstatus, MimeType, expired, favouritesindex, accessibility, isdownloaded,))
changed = False
try:
@@ -1503,7 +1502,7 @@ class KOBOTOUCH(KOBO):
# print "Normalized FileName: " + path
idx = bl_cache.get(lpath, None)
- if idx is not None:# and not (accessibility == 1 and isdownloaded == 'false'):
+ if idx is not None: # and not (accessibility == 1 and isdownloaded == 'false'):
if show_debug:
self.debug_index = idx
debug_print("KoboTouch:update_booklist - idx=%d"%idx)
@@ -1556,7 +1555,7 @@ class KOBOTOUCH(KOBO):
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:
- if isdownloaded == 'true': # A recommendation or preview is OK to not have a file
+ if isdownloaded == 'true': # A recommendation or preview is OK to not have a file
debug_print(" Strange: The file: ", prefix, lpath, " does not exist!")
title = "FILE MISSING: " + title
book = self.book_class(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=0)
@@ -1565,7 +1564,7 @@ class KOBOTOUCH(KOBO):
except Exception as e:
debug_print("KoboTouch:update_booklist - exception creating book: '%s'"%str(e))
- debug_print(" prefix: ", prefix, "lpath: ", lpath, "title: ", title, "authors: ", authors, \
+ debug_print(" prefix: ", prefix, "lpath: ", lpath, "title: ", title, "authors: ", authors,
"mime: ", mime, "date: ", date, "ContentType: ", ContentType, "ImageID: ", ImageID)
raise
@@ -1580,7 +1579,7 @@ class KOBOTOUCH(KOBO):
debug_print(" kobo_collections:", kobo_collections)
# print 'Update booklist'
- book.device_collections = playlist_map.get(lpath,[])# if lpath in playlist_map else []
+ book.device_collections = playlist_map.get(lpath,[]) # if lpath in playlist_map else []
book.current_shelves = bookshelves
book.kobo_collections = kobo_collections
book.contentID = ContentID
@@ -1594,7 +1593,7 @@ class KOBOTOUCH(KOBO):
if show_debug:
debug_print(' book.device_collections', book.device_collections)
debug_print(' book.title', book.title)
- except: # Probably a path encoding error
+ except: # Probably a path encoding error
import traceback
traceback.print_exc()
return changed
@@ -1656,50 +1655,53 @@ class KOBOTOUCH(KOBO):
where_clause = ''
if self.supports_kobo_archive():
- where_clause = (" where BookID is Null " \
- " and ((Accessibility = -1 and IsDownloaded in ('true', 1 )) or (Accessibility in (1,2) %(expiry)s) " \
- " %(previews)s %(recomendations)s )" \
+ where_clause = (" where BookID is Null "
+ " and ((Accessibility = -1 and IsDownloaded in ('true', 1 )) or (Accessibility in (1,2) %(expiry)s) "
+ " %(previews)s %(recomendations)s )"
" and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) and ContentType = 6)") % \
- dict(\
- expiry="" if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else "and IsDownloaded in ('true', 1)", \
- previews=" or (Accessibility in (6) and ___UserID <> '')" if opts.extra_customization[self.OPT_SHOW_PREVIEWS] else "", \
- recomendations=" or (Accessibility in (-1, 4, 6) and ___UserId = '')" if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] else "" \
+ dict(
+ expiry="" if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else "and IsDownloaded in ('true', 1)",
+ previews=" or (Accessibility in (6) and ___UserID <> '')" if opts.extra_customization[self.OPT_SHOW_PREVIEWS] else "",
+ recomendations=" or (Accessibility in (-1, 4, 6) and ___UserId = '')" if opts.extra_customization[
+ self.OPT_SHOW_RECOMMENDATIONS] else ""
)
elif self.supports_series():
- where_clause = (" where BookID is Null " \
- " and ((Accessibility = -1 and IsDownloaded in ('true', 1)) or (Accessibility in (1,2)) %(previews)s %(recomendations)s )" \
+ where_clause = (" where BookID is Null "
+ " and ((Accessibility = -1 and IsDownloaded in ('true', 1)) or (Accessibility in (1,2)) %(previews)s %(recomendations)s )"
" and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s)") % \
- dict(\
- expiry=" and ContentType = 6" if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else "", \
- previews=" or (Accessibility in (6) and ___UserID <> '')" if opts.extra_customization[self.OPT_SHOW_PREVIEWS] else "", \
- recomendations=" or (Accessibility in (-1, 4, 6) and ___UserId = '')" if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] else "" \
+ dict(
+ expiry=" and ContentType = 6" if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else "",
+ previews=" or (Accessibility in (6) and ___UserID <> '')" if opts.extra_customization[self.OPT_SHOW_PREVIEWS] else "",
+ recomendations=" or (Accessibility in (-1, 4, 6) and ___UserId = '')" if opts.extra_customization[
+ self.OPT_SHOW_RECOMMENDATIONS] else ""
)
elif self.dbversion >= 33:
where_clause = (' where BookID is Null %(previews)s %(recomendations)s and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s)') % \
- dict(\
- expiry=' and ContentType = 6' if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else '', \
- previews=' and Accessibility <> 6' if opts.extra_customization[self.OPT_SHOW_PREVIEWS] == False else '', \
- recomendations=' and IsDownloaded in (\'true\', 1)' if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] == False else ''\
+ dict(
+ expiry=' and ContentType = 6' if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else '',
+ previews=' and Accessibility <> 6' if opts.extra_customization[self.OPT_SHOW_PREVIEWS] == False else '',
+ recomendations=' and IsDownloaded in (\'true\', 1)' if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] == False else ''
)
elif self.dbversion >= 16:
- where_clause = (' where BookID is Null ' \
+ where_clause = (' where BookID is Null '
'and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s)') % \
dict(expiry=' and ContentType = 6' if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else '')
else:
where_clause = ' where BookID is Null'
- # Note: The card condition should not need the contentId test for the SD card. But the ExternalId does not get set for sideloaded kepubs on the SD card.
+ # Note: The card condition should not need the contentId test for the SD
+ # card. But the ExternalId does not get set for sideloaded kepubs on the
+ # SD card.
card_condition = ''
if self.has_externalid():
card_condition = " AND (externalId IS NOT NULL AND externalId <> '' OR contentId LIKE 'file:///mnt/sd/%')" if oncard == 'carda' else " AND (externalId IS NULL OR externalId = '') AND contentId NOT LIKE 'file:///mnt/sd/%'"
else:
card_condition = " AND contentId LIKE 'file:///mnt/sd/%'" if oncard == 'carda' else " AND contentId NOT LIKE'file:///mnt/sd/%'"
-
query = 'SELECT ' + columns + ' FROM content ' + where_clause + card_condition
debug_print("KoboTouch:books - query=", query)
try:
- cursor.execute (query)
+ cursor.execute(query)
except Exception as e:
err = str(e)
if not ('___ExpirationStatus' in err
@@ -1712,7 +1714,7 @@ class KOBOTOUCH(KOBO):
raise
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
'ImageID, ReadStatus, "-1" as ___ExpirationStatus, "-1" as '
- 'FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded, null as Series, null as SeriesNumber' \
+ 'FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded, null as Series, null as SeriesNumber'
' from content where BookID is Null')
cursor.execute(query)
@@ -1737,7 +1739,8 @@ class KOBOTOUCH(KOBO):
bookshelves = get_bookshelvesforbook(connection, row[3])
prefix = self._card_a_prefix if oncard == 'carda' else self._main_prefix
- changed = update_booklist(prefix, path, row[0], row[1], mime, row[2], row[3], row[5], row[6], row[7], row[4], row[8], row[9], row[10], row[11], row[12], row[13], row[14], bookshelves)
+ changed = update_booklist(prefix, path, row[0], row[1], mime, row[2], row[3], row[5], row[
+ 6], row[7], row[4], row[8], row[9], row[10], row[11], row[12], row[13], row[14], bookshelves)
if changed:
need_sync = True
@@ -1759,11 +1762,11 @@ class KOBOTOUCH(KOBO):
# else:
# debug_print("KoboTouch:books - Book in mtadata.calibre, on file system but not database - bl[idx].title:'%s'"%bl[idx].title)
- #print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
+ # print "count found in cache: %d, count of files in metadata: %d, need_sync: %s" % \
# (len(bl_cache), len(bl), need_sync)
# Bypassing the KOBO sync_booklists as that does things we don't need to do
# Also forcing sync to see if this solves issues with updating shelves and matching books.
- if need_sync or True: #self.count_found_in_bl != len(bl) or need_sync:
+ if need_sync or True: # self.count_found_in_bl != len(bl) or need_sync:
debug_print("KoboTouch:books - about to sync_booklists")
if oncard == 'cardb':
USBMS.sync_booklists(self, (None, None, bl))
@@ -1786,7 +1789,7 @@ class KOBOTOUCH(KOBO):
if oncard == 'cardb':
print 'path from_contentid cardb'
else:
- if (ContentType == "6" or ContentType == "10"): # and MimeType == 'application/x-kobo-epub+zip':
+ if (ContentType == "6" or ContentType == "10"): # and MimeType == 'application/x-kobo-epub+zip':
if path.startswith("file:///mnt/onboard/"):
path = self._main_prefix + path.replace("file:///mnt/onboard/", '')
elif path.startswith("file:///mnt/sd/"):
@@ -1804,7 +1807,6 @@ class KOBOTOUCH(KOBO):
return path
-
def imagefilename_from_imageID(self, prefix, ImageID):
show_debug = self.is_debugging_title(ImageID)
@@ -1822,10 +1824,9 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:imagefilename_from_imageID - no cover image found - ImageID=%s" % (ImageID))
return None
-
def get_extra_css(self):
extra_sheet = None
-
+
if self.modifying_css():
extra_css_path = os.path.join(self._main_prefix, self.KOBO_EXTRA_CSSFILE)
if os.path.exists(extra_css_path):
@@ -1838,7 +1839,6 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:get_extra_css: Exception {0}".format(e))
return extra_sheet
-
def upload_books(self, files, names, on_card=None, end_session=True,
metadata=None):
debug_print('KoboTouch:upload_books - %d books'%(len(files)))
@@ -1891,13 +1891,11 @@ class KOBOTOUCH(KOBO):
except Exception as e:
debug_print('KoboTouch:upload_books - Exception: %s'%str(e))
-
return result
-
def _modify_epub(self, file, metadata, container=None):
debug_print("KoboTouch:_modify_epub:Processing {0} - {1}".format(metadata.author_sort, metadata.title))
-
+
# Currently only modifying CSS, so if no stylesheet, don't do anything
if not self.extra_sheet:
return True
@@ -1924,7 +1922,7 @@ class KOBOTOUCH(KOBO):
if mt in OEB_STYLES:
newsheet = container.parsed(cssname)
oldrules = len(newsheet.cssRules)
- # remove any existing @page rules in epub css
+ # remove any existing @page rules in epub css
# if css to be appended contains an @page rule
if self.extra_sheet and len([r for r in self.extra_sheet if r.type == r.PAGE_RULE]):
page_rules = [r for r in newsheet if r.type == r.PAGE_RULE]
@@ -1932,11 +1930,11 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:_modify_epub:Removing existing @page rules")
for rule in page_rules:
rule.style = ''
- # remove any existing widow/orphan settings in epub css
- # if css to be appended contains a widow/orphan rule or we there is no extra CSS file
- if (len([r for r in self.extra_sheet if r.type == r.STYLE_RULE \
+ # remove any existing widow/orphan settings in epub css
+ # if css to be appended contains a widow/orphan rule or we there is no extra CSS file
+ if (len([r for r in self.extra_sheet if r.type == r.STYLE_RULE
and (r.style['widows'] or r.style['orphans'])]) > 0):
- widow_orphan_rules = [r for r in newsheet if r.type == r.STYLE_RULE \
+ widow_orphan_rules = [r for r in newsheet if r.type == r.STYLE_RULE
and (r.style['widows'] or r.style['orphans'])]
if len(widow_orphan_rules) > 0:
debug_print("KoboTouch:_modify_epub:Removing existing widows/orphans attribs")
@@ -1956,7 +1954,6 @@ class KOBOTOUCH(KOBO):
return True
-
def delete_via_sql(self, ContentID, ContentType):
imageId = super(KOBOTOUCH, self).delete_via_sql(ContentID, ContentType)
@@ -1972,7 +1969,7 @@ class KOBOTOUCH(KOBO):
cursor = connection.cursor()
debug_print('KoboTouch:delete_via_sql: have cursor')
t = (ContentID,)
- #Delete from the Bookshelf
+ # Delete from the Bookshelf
debug_print('KoboTouch:delete_via_sql: Delete from the Bookshelf')
cursor.execute('delete from ShelfContent where ContentID = ?', t)
@@ -2044,7 +2041,7 @@ class KOBOTOUCH(KOBO):
if self._card_a_prefix is not None:
ContentID = ContentID.replace(self._card_a_prefix, "file:///mnt/sd/")
- else: # ContentType = 16
+ else: # ContentType = 16
debug_print("KoboTouch:contentid_from_path ContentType other than 6 - ContentType='%d'"%ContentType, "path='%s'"%path)
ContentID = path
ContentID = ContentID.replace(self._main_prefix, "file:///mnt/onboard/")
@@ -2108,7 +2105,7 @@ class KOBOTOUCH(KOBO):
delete_empty_shelves = opts.extra_customization[self.OPT_DELETE_BOOKSHELVES] and self.supports_bookshelves()
update_series_details = opts.extra_customization[self.OPT_UPDATE_SERIES_DETAILS] and self.supports_series()
debugging_title = opts.extra_customization[self.OPT_DEBUGGING_TITLE]
- debug_print("KoboTouch:update_device_database_collections - set_debugging_title to '%s'" % debugging_title )
+ debug_print("KoboTouch:update_device_database_collections - set_debugging_title to '%s'" % debugging_title)
booklists.set_debugging_title(debugging_title)
else:
delete_empty_shelves = False
@@ -2213,7 +2210,7 @@ class KOBOTOUCH(KOBO):
debug_print(' category not added to book.device_collections', book.device_collections)
debug_print("KoboTouch:update_device_database_collections - end for category='%s'"%category)
- else: # No collections
+ else: # No collections
# Since no collections exist the ReadStatus needs to be reset to 0 (Unread)
debug_print("No Collections - reseting ReadStatus")
if self.dbversion < 53:
@@ -2247,7 +2244,6 @@ class KOBOTOUCH(KOBO):
self.dump_bookshelves(connection)
-
debug_print('KoboTouch:update_device_database_collections - Finished ')
def rebuild_collections(self, booklist, oncard):
@@ -2292,7 +2288,6 @@ class KOBOTOUCH(KOBO):
except Exception as e:
debug_print('KoboTouch: FAILED to upload cover=%s Exception=%s'%(filepath, str(e)))
-
def imageid_from_contentid(self, ContentID):
ImageID = ContentID.replace('/', '_')
ImageID = ImageID.replace(' ', '_')
@@ -2300,7 +2295,6 @@ class KOBOTOUCH(KOBO):
ImageID = ImageID.replace('.', '_')
return ImageID
-
def images_path(self, path):
if self._card_a_prefix and os.path.abspath(path).startswith(os.path.abspath(self._card_a_prefix)) and self.supports_covers_on_sdcard():
path_prefix = 'koboExtStorage/images/'
@@ -2367,7 +2361,7 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:_upload_cover - resize=%s min_dbversion=%d max_dbversion=%d" % (resize, min_dbversion, max_dbversion))
if self.dbversion >= min_dbversion and self.dbversion <= max_dbversion:
if show_debug:
- debug_print("KoboTouch:_upload_cover - creating cover for ending='%s'"%ending)#, "resize'%s'"%resize)
+ debug_print("KoboTouch:_upload_cover - creating cover for ending='%s'"%ending) # , "resize'%s'"%resize)
fpath = path + ending
fpath = self.normalize_path(fpath.replace('/', os.sep))
@@ -2381,9 +2375,9 @@ class KOBOTOUCH(KOBO):
width, height, fmt = identify_data(data)
cover_aspect = width / height
if cover_aspect > 1:
- resize = (resize[0], int(resize[0] / cover_aspect ))
+ resize = (resize[0], int(resize[0] / cover_aspect))
elif cover_aspect < 1:
- resize = (int(cover_aspect * resize[1]), resize[1] )
+ resize = (int(cover_aspect * resize[1]), resize[1])
# Return the data resized and in Grayscale if
# required
@@ -2402,7 +2396,7 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:_upload_cover - ImageID could not be retrieved from the database")
def remove_book_from_device_bookshelves(self, connection, book):
- show_debug = self.is_debugging_title(book.title)# or True
+ show_debug = self.is_debugging_title(book.title) # or True
remove_shelf_list = set(book.current_shelves) - set(book.device_collections)
@@ -2687,7 +2681,6 @@ class KOBOTOUCH(KOBO):
if show_debug:
debug_print("KoboTouch:set_series - end")
-
@classmethod
def settings(cls):
opts = cls._config().parse()
@@ -2710,7 +2703,6 @@ class KOBOTOUCH(KOBO):
opts.extra_customization = extra_customization
return opts
-
def isAuraHD(self):
return self.detected_device.idProduct in self.AURA_HD_PRODUCT_ID
def isGlo(self):
@@ -2736,7 +2728,6 @@ class KOBOTOUCH(KOBO):
self.__class__.gui_name = device_name
return device_name
-
def copying_covers(self):
opts = self.settings()
return opts.extra_customization[self.OPT_UPLOAD_COVERS] or opts.extra_customization[self.OPT_KEEP_COVER_ASPECT_RATIO]
@@ -2752,7 +2743,6 @@ class KOBOTOUCH(KOBO):
opts = self.settings()
return opts.extra_customization[self.OPT_MODIFY_CSS]
-
def supports_bookshelves(self):
return self.dbversion >= self.min_supported_dbversion
@@ -2806,7 +2796,6 @@ class KOBOTOUCH(KOBO):
# Supported database version
return True
-
@classmethod
def is_debugging_title(cls, title):
if not DEBUG:
@@ -2858,3 +2847,4 @@ class KOBOTOUCH(KOBO):
cursor.close()
debug_print('KoboTouch:dump_bookshelves - end')
+