mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8 cleanup of kobo/driver.py
Kobo driver: Add an option to modify the styling in books being sent to the device, based on a template on the device. Fixes #1207151 [Append and modify CSS when sending epubs to Kobo devices](https://bugs.launchpad.net/calibre/+bug/1207151)
This commit is contained in:
parent
08819cb340
commit
20caf3ac99
@ -75,8 +75,8 @@ class KOBO(USBMS):
|
|||||||
VIRTUAL_BOOK_EXTENSIONS = frozenset(['kobo', ''])
|
VIRTUAL_BOOK_EXTENSIONS = frozenset(['kobo', ''])
|
||||||
|
|
||||||
EXTRA_CUSTOMIZATION_MESSAGE = [
|
EXTRA_CUSTOMIZATION_MESSAGE = [
|
||||||
_('The Kobo supports several collections including ')+\
|
_('The Kobo supports several collections including ')+
|
||||||
'Read, Closed, Im_Reading. ' +\
|
'Read, Closed, Im_Reading. ' +
|
||||||
_('Create tags for automatic management'),
|
_('Create tags for automatic management'),
|
||||||
_('Upload covers for books (newer readers)') +
|
_('Upload covers for books (newer readers)') +
|
||||||
':::'+_('Normally, the KOBO readers get the cover image from the'
|
':::'+_('Normally, the KOBO readers get the cover image from the'
|
||||||
@ -248,7 +248,7 @@ class KOBO(USBMS):
|
|||||||
book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=1048576)
|
book = Book(prefix, lpath, title, authors, mime, date, ContentType, ImageID, size=1048576)
|
||||||
|
|
||||||
except:
|
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)
|
"mime: ", mime, "date: ", date, "ContentType: ", ContentType, "ImageID: ", ImageID)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -280,28 +280,28 @@ class KOBO(USBMS):
|
|||||||
|
|
||||||
opts = self.settings()
|
opts = self.settings()
|
||||||
if self.dbversion >= 33:
|
if self.dbversion >= 33:
|
||||||
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
|
||||||
'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, Accessibility, IsDownloaded from content where ' \
|
'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)' \
|
'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 ')', \
|
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')',
|
||||||
previews=' and Accessibility <> 6' \
|
previews=' and Accessibility <> 6'
|
||||||
if opts.extra_customization[self.OPT_SHOW_PREVIEWS] == False else '', \
|
if opts.extra_customization[self.OPT_SHOW_PREVIEWS] == False else '',
|
||||||
recomendations=' and IsDownloaded in (\'true\', 1)' \
|
recomendations=' and IsDownloaded in (\'true\', 1)'
|
||||||
if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] == False else '')
|
if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] == False else '')
|
||||||
elif self.dbversion >= 16 and self.dbversion < 33:
|
elif self.dbversion >= 16 and self.dbversion < 33:
|
||||||
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
|
||||||
'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, Accessibility, "1" as IsDownloaded from content where ' \
|
'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)' \
|
'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 ')')
|
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')')
|
||||||
elif self.dbversion < 16 and self.dbversion >= 14:
|
elif self.dbversion < 16 and self.dbversion >= 14:
|
||||||
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
|
||||||
'ImageID, ReadStatus, ___ExpirationStatus, FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where ' \
|
'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)' \
|
'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 ')')
|
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')')
|
||||||
elif self.dbversion < 14 and self.dbversion >= 8:
|
elif self.dbversion < 14 and self.dbversion >= 8:
|
||||||
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
|
||||||
'ImageID, ReadStatus, ___ExpirationStatus, "-1" as FavouritesIndex, "-1" as Accessibility, "1" as IsDownloaded from content where ' \
|
'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)' \
|
'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 ')')
|
if opts.extra_customization[self.OPT_SHOW_EXPIRED_BOOK_RECORDS] else ')')
|
||||||
else:
|
else:
|
||||||
query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
||||||
@ -405,18 +405,18 @@ class KOBO(USBMS):
|
|||||||
cursor.execute('delete from content where BookID = ?', t)
|
cursor.execute('delete from content where BookID = ?', t)
|
||||||
if ContentType == 6:
|
if ContentType == 6:
|
||||||
try:
|
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)
|
'where BookID is Null and ContentID =?',t)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if 'no such column' not in str(e):
|
if 'no such column' not in str(e):
|
||||||
raise
|
raise
|
||||||
try:
|
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)
|
'where BookID is Null and ContentID =?',t)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if 'no such column' not in str(e):
|
if 'no such column' not in str(e):
|
||||||
raise
|
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)
|
'where BookID is Null and ContentID =?',t)
|
||||||
else:
|
else:
|
||||||
cursor.execute('delete from content where BookID is Null and ContentID =?',t)
|
cursor.execute('delete from content where BookID is Null and ContentID =?',t)
|
||||||
@ -436,7 +436,8 @@ class KOBO(USBMS):
|
|||||||
path_prefix = '.kobo/images/'
|
path_prefix = '.kobo/images/'
|
||||||
path = self._main_prefix + path_prefix + ImageID
|
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:
|
for ending in file_endings:
|
||||||
fpath = path + ending
|
fpath = path + ending
|
||||||
@ -857,7 +858,6 @@ class KOBO(USBMS):
|
|||||||
|
|
||||||
# debug_print('Finished update_device_database_collections', collections_attributes)
|
# debug_print('Finished update_device_database_collections', collections_attributes)
|
||||||
|
|
||||||
|
|
||||||
def get_collections_attributes(self):
|
def get_collections_attributes(self):
|
||||||
collections = []
|
collections = []
|
||||||
opts = self.settings()
|
opts = self.settings()
|
||||||
@ -1107,13 +1107,13 @@ class KOBO(USBMS):
|
|||||||
spanTag['style'] = 'font-weight:normal'
|
spanTag['style'] = 'font-weight:normal'
|
||||||
if bookmark.book_format == 'epub':
|
if bookmark.book_format == 'epub':
|
||||||
spanTag.insert(0,NavigableString(
|
spanTag.insert(0,NavigableString(
|
||||||
_("<hr /><b>Book Last Read:</b> %(time)s<br /><b>Percentage Read:</b> %(pr)d%%<hr />") % \
|
_("<hr /><b>Book Last Read:</b> %(time)s<br /><b>Percentage Read:</b> %(pr)d%%<hr />") %
|
||||||
dict(time=last_read,
|
dict(time=last_read,
|
||||||
# loc=last_read_location,
|
# loc=last_read_location,
|
||||||
pr=percent_read)))
|
pr=percent_read)))
|
||||||
else:
|
else:
|
||||||
spanTag.insert(0,NavigableString(
|
spanTag.insert(0,NavigableString(
|
||||||
_("<hr /><b>Book Last Read:</b> %(time)s<br /><b>Percentage Read:</b> %(pr)d%%<hr />") % \
|
_("<hr /><b>Book Last Read:</b> %(time)s<br /><b>Percentage Read:</b> %(pr)d%%<hr />") %
|
||||||
dict(time=last_read,
|
dict(time=last_read,
|
||||||
# loc=last_read_location,
|
# loc=last_read_location,
|
||||||
pr=percent_read)))
|
pr=percent_read)))
|
||||||
@ -1131,7 +1131,7 @@ class KOBO(USBMS):
|
|||||||
for location in sorted(user_notes):
|
for location in sorted(user_notes):
|
||||||
if user_notes[location]['type'] == 'Bookmark':
|
if user_notes[location]['type'] == 'Bookmark':
|
||||||
annotations.append(
|
annotations.append(
|
||||||
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br />%(annotation)s<br /><hr />') % \
|
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br />%(annotation)s<br /><hr />') %
|
||||||
dict(chapter=user_notes[location]['chapter'],
|
dict(chapter=user_notes[location]['chapter'],
|
||||||
dl=user_notes[location]['displayed_location'],
|
dl=user_notes[location]['displayed_location'],
|
||||||
typ=user_notes[location]['type'],
|
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 ""))
|
annotation=user_notes[location]['annotation'] if user_notes[location]['annotation'] is not None else ""))
|
||||||
elif user_notes[location]['type'] == 'Highlight':
|
elif user_notes[location]['type'] == 'Highlight':
|
||||||
annotations.append(
|
annotations.append(
|
||||||
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br /><b>Highlight:</b> %(text)s<br /><hr />') % \
|
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br /><b>Highlight:</b> %(text)s<br /><hr />') %
|
||||||
dict(chapter=user_notes[location]['chapter'],
|
dict(chapter=user_notes[location]['chapter'],
|
||||||
dl=user_notes[location]['displayed_location'],
|
dl=user_notes[location]['displayed_location'],
|
||||||
typ=user_notes[location]['type'],
|
typ=user_notes[location]['type'],
|
||||||
@ -1149,7 +1149,7 @@ class KOBO(USBMS):
|
|||||||
text=user_notes[location]['text']))
|
text=user_notes[location]['text']))
|
||||||
elif user_notes[location]['type'] == 'Annotation':
|
elif user_notes[location]['type'] == 'Annotation':
|
||||||
annotations.append(
|
annotations.append(
|
||||||
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br /><b>Highlight:</b> %(text)s<br /><b>Notes:</b> %(annotation)s<br /><hr />') % \
|
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br /><b>Highlight:</b> %(text)s<br /><b>Notes:</b> %(annotation)s<br /><hr />') %
|
||||||
dict(chapter=user_notes[location]['chapter'],
|
dict(chapter=user_notes[location]['chapter'],
|
||||||
dl=user_notes[location]['displayed_location'],
|
dl=user_notes[location]['displayed_location'],
|
||||||
typ=user_notes[location]['type'],
|
typ=user_notes[location]['type'],
|
||||||
@ -1159,13 +1159,13 @@ class KOBO(USBMS):
|
|||||||
annotation=user_notes[location]['annotation']))
|
annotation=user_notes[location]['annotation']))
|
||||||
else:
|
else:
|
||||||
annotations.append(
|
annotations.append(
|
||||||
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br /><b>Highlight:</b> %(text)s<br /><b>Notes:</b> %(annotation)s<br /><hr />') % \
|
_('<b>Chapter %(chapter)d:</b> %(chapter_title)s<br /><b>%(typ)s</b><br /><b>Chapter Progress:</b> %(chapter_progress)s%%<br /><b>Highlight:</b> %(text)s<br /><b>Notes:</b> %(annotation)s<br /><hr />') %
|
||||||
dict(chapter=user_notes[location]['chapter'],
|
dict(chapter=user_notes[location]['chapter'],
|
||||||
dl=user_notes[location]['displayed_location'],
|
dl=user_notes[location]['displayed_location'],
|
||||||
typ=user_notes[location]['type'],
|
typ=user_notes[location]['type'],
|
||||||
chapter_title=user_notes[location]['chapter_title'],
|
chapter_title=user_notes[location]['chapter_title'],
|
||||||
chapter_progress=user_notes[location]['chapter_progress'],
|
chapter_progress=user_notes[location]['chapter_progress'],
|
||||||
text=user_notes[location]['text'], \
|
text=user_notes[location]['text'],
|
||||||
annotation=user_notes[location]['annotation']))
|
annotation=user_notes[location]['annotation']))
|
||||||
|
|
||||||
for annotation in annotations:
|
for annotation in annotations:
|
||||||
@ -1240,8 +1240,8 @@ class KOBOTOUCH(KOBO):
|
|||||||
KOBO_EXTRA_CSSFILE = 'kobo_extra.css'
|
KOBO_EXTRA_CSSFILE = 'kobo_extra.css'
|
||||||
|
|
||||||
EXTRA_CUSTOMIZATION_MESSAGE = [
|
EXTRA_CUSTOMIZATION_MESSAGE = [
|
||||||
_('The Kobo Touch from firmware V2.0.0 supports bookshelves.')+\
|
_('The Kobo Touch from firmware V2.0.0 supports bookshelves.')+
|
||||||
'These are created on the Kobo Touch. ' +\
|
'These are created on the Kobo Touch. ' +
|
||||||
_('Specify a tags type column for automatic management'),
|
_('Specify a tags type column for automatic management'),
|
||||||
_('Create Bookshelves') +
|
_('Create Bookshelves') +
|
||||||
':::'+_('Create new bookshelves on the Kobo Touch if they do not exist. This is only for firmware V2.0.0 or later.'),
|
':::'+_('Create new bookshelves on the Kobo Touch if they do not exist. This is only for firmware V2.0.0 or later.'),
|
||||||
@ -1352,14 +1352,13 @@ class KOBOTOUCH(KOBO):
|
|||||||
# Following are the sizes used with pre2.1.4 firmware
|
# Following are the sizes used with pre2.1.4 firmware
|
||||||
# COVER_FILE_ENDINGS = {
|
# COVER_FILE_ENDINGS = {
|
||||||
# ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], # Used for Details screen
|
# ' - N3_LIBRARY_FULL.parsed':[(355,530),0, 99,], # Used for Details screen
|
||||||
## ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,],
|
# ' - N3_LIBRARY_FULL.parsed':[(600,800),0, 99,],
|
||||||
# ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], # Used for library lists
|
# ' - N3_LIBRARY_GRID.parsed':[(149,233),0, 99,], # Used for library lists
|
||||||
# ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,],
|
# ' - N3_LIBRARY_LIST.parsed':[(60,90),0, 53,],
|
||||||
# ' - N3_LIBRARY_SHELF.parsed': [(40,60),0, 52,],
|
# ' - 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):
|
def initialize(self):
|
||||||
super(KOBOTOUCH, self).initialize()
|
super(KOBOTOUCH, self).initialize()
|
||||||
self.bookshelvelist = []
|
self.bookshelvelist = []
|
||||||
@ -1368,7 +1367,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
self.set_device_name()
|
self.set_device_name()
|
||||||
return super(KOBOTOUCH, self).get_device_information(end_session)
|
return super(KOBOTOUCH, self).get_device_information(end_session)
|
||||||
|
|
||||||
|
|
||||||
def books(self, oncard=None, end_session=True):
|
def books(self, oncard=None, end_session=True):
|
||||||
debug_print("KoboTouch:books - oncard='%s'"%oncard)
|
debug_print("KoboTouch:books - oncard='%s'"%oncard)
|
||||||
from calibre.ebooks.metadata.meta import path_to_ext
|
from calibre.ebooks.metadata.meta import path_to_ext
|
||||||
@ -1431,7 +1429,8 @@ class KOBOTOUCH(KOBO):
|
|||||||
# show_debug = authors == 'L. Frank Baum'
|
# show_debug = authors == 'L. Frank Baum'
|
||||||
if show_debug:
|
if show_debug:
|
||||||
debug_print("KoboTouch:update_booklist - title='%s'"%title, "ContentType=%s"%ContentType, "isdownloaded=", isdownloaded)
|
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,))
|
(prefix, mime, date, readstatus, MimeType, expired, favouritesindex, accessibility, isdownloaded,))
|
||||||
changed = False
|
changed = False
|
||||||
try:
|
try:
|
||||||
@ -1565,7 +1564,7 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug_print("KoboTouch:update_booklist - exception creating book: '%s'"%str(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)
|
"mime: ", mime, "date: ", date, "ContentType: ", ContentType, "ImageID: ", ImageID)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -1656,46 +1655,49 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
where_clause = ''
|
where_clause = ''
|
||||||
if self.supports_kobo_archive():
|
if self.supports_kobo_archive():
|
||||||
where_clause = (" where BookID is Null " \
|
where_clause = (" where BookID is Null "
|
||||||
" and ((Accessibility = -1 and IsDownloaded in ('true', 1 )) or (Accessibility in (1,2) %(expiry)s) " \
|
" and ((Accessibility = -1 and IsDownloaded in ('true', 1 )) or (Accessibility in (1,2) %(expiry)s) "
|
||||||
" %(previews)s %(recomendations)s )" \
|
" %(previews)s %(recomendations)s )"
|
||||||
" and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) and ContentType = 6)") % \
|
" and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) and ContentType = 6)") % \
|
||||||
dict(\
|
dict(
|
||||||
expiry="" if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else "and IsDownloaded in ('true', 1)", \
|
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 "", \
|
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 "" \
|
recomendations=" or (Accessibility in (-1, 4, 6) and ___UserId = '')" if opts.extra_customization[
|
||||||
|
self.OPT_SHOW_RECOMMENDATIONS] else ""
|
||||||
)
|
)
|
||||||
elif self.supports_series():
|
elif self.supports_series():
|
||||||
where_clause = (" where BookID is Null " \
|
where_clause = (" where BookID is Null "
|
||||||
" and ((Accessibility = -1 and IsDownloaded in ('true', 1)) or (Accessibility in (1,2)) %(previews)s %(recomendations)s )" \
|
" 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)") % \
|
" and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s)") % \
|
||||||
dict(\
|
dict(
|
||||||
expiry=" and ContentType = 6" if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else "", \
|
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 "", \
|
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 "" \
|
recomendations=" or (Accessibility in (-1, 4, 6) and ___UserId = '')" if opts.extra_customization[
|
||||||
|
self.OPT_SHOW_RECOMMENDATIONS] else ""
|
||||||
)
|
)
|
||||||
elif self.dbversion >= 33:
|
elif self.dbversion >= 33:
|
||||||
where_clause = (' where BookID is Null %(previews)s %(recomendations)s and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s)') % \
|
where_clause = (' where BookID is Null %(previews)s %(recomendations)s and not ((___ExpirationStatus=3 or ___ExpirationStatus is Null) %(expiry)s)') % \
|
||||||
dict(\
|
dict(
|
||||||
expiry=' and ContentType = 6' if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else '', \
|
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 '', \
|
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 ''\
|
recomendations=' and IsDownloaded in (\'true\', 1)' if opts.extra_customization[self.OPT_SHOW_RECOMMENDATIONS] == False else ''
|
||||||
)
|
)
|
||||||
elif self.dbversion >= 16:
|
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)') % \
|
'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 '')
|
dict(expiry=' and ContentType = 6' if opts.extra_customization[self.OPT_SHOW_ARCHIVED_BOOK_RECORDS] else '')
|
||||||
else:
|
else:
|
||||||
where_clause = ' where BookID is Null'
|
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 = ''
|
card_condition = ''
|
||||||
if self.has_externalid():
|
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/%'"
|
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:
|
else:
|
||||||
card_condition = " AND contentId LIKE 'file:///mnt/sd/%'" if oncard == 'carda' else " AND contentId NOT LIKE'file:///mnt/sd/%'"
|
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
|
query = 'SELECT ' + columns + ' FROM content ' + where_clause + card_condition
|
||||||
debug_print("KoboTouch:books - query=", query)
|
debug_print("KoboTouch:books - query=", query)
|
||||||
try:
|
try:
|
||||||
@ -1712,7 +1714,7 @@ class KOBOTOUCH(KOBO):
|
|||||||
raise
|
raise
|
||||||
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
|
query= ('select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, '
|
||||||
'ImageID, ReadStatus, "-1" as ___ExpirationStatus, "-1" as '
|
'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')
|
' from content where BookID is Null')
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
||||||
@ -1737,7 +1739,8 @@ class KOBOTOUCH(KOBO):
|
|||||||
bookshelves = get_bookshelvesforbook(connection, row[3])
|
bookshelves = get_bookshelvesforbook(connection, row[3])
|
||||||
|
|
||||||
prefix = self._card_a_prefix if oncard == 'carda' else self._main_prefix
|
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:
|
if changed:
|
||||||
need_sync = True
|
need_sync = True
|
||||||
@ -1804,7 +1807,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def imagefilename_from_imageID(self, prefix, ImageID):
|
def imagefilename_from_imageID(self, prefix, ImageID):
|
||||||
show_debug = self.is_debugging_title(ImageID)
|
show_debug = self.is_debugging_title(ImageID)
|
||||||
|
|
||||||
@ -1822,7 +1824,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
debug_print("KoboTouch:imagefilename_from_imageID - no cover image found - ImageID=%s" % (ImageID))
|
debug_print("KoboTouch:imagefilename_from_imageID - no cover image found - ImageID=%s" % (ImageID))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_extra_css(self):
|
def get_extra_css(self):
|
||||||
extra_sheet = None
|
extra_sheet = None
|
||||||
|
|
||||||
@ -1838,7 +1839,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
debug_print("KoboTouch:get_extra_css: Exception {0}".format(e))
|
debug_print("KoboTouch:get_extra_css: Exception {0}".format(e))
|
||||||
return extra_sheet
|
return extra_sheet
|
||||||
|
|
||||||
|
|
||||||
def upload_books(self, files, names, on_card=None, end_session=True,
|
def upload_books(self, files, names, on_card=None, end_session=True,
|
||||||
metadata=None):
|
metadata=None):
|
||||||
debug_print('KoboTouch:upload_books - %d books'%(len(files)))
|
debug_print('KoboTouch:upload_books - %d books'%(len(files)))
|
||||||
@ -1891,10 +1891,8 @@ class KOBOTOUCH(KOBO):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug_print('KoboTouch:upload_books - Exception: %s'%str(e))
|
debug_print('KoboTouch:upload_books - Exception: %s'%str(e))
|
||||||
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _modify_epub(self, file, metadata, container=None):
|
def _modify_epub(self, file, metadata, container=None):
|
||||||
debug_print("KoboTouch:_modify_epub:Processing {0} - {1}".format(metadata.author_sort, metadata.title))
|
debug_print("KoboTouch:_modify_epub:Processing {0} - {1}".format(metadata.author_sort, metadata.title))
|
||||||
|
|
||||||
@ -1934,9 +1932,9 @@ class KOBOTOUCH(KOBO):
|
|||||||
rule.style = ''
|
rule.style = ''
|
||||||
# remove any existing widow/orphan settings in epub css
|
# 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 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 \
|
if (len([r for r in self.extra_sheet if r.type == r.STYLE_RULE
|
||||||
and (r.style['widows'] or r.style['orphans'])]) > 0):
|
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'])]
|
and (r.style['widows'] or r.style['orphans'])]
|
||||||
if len(widow_orphan_rules) > 0:
|
if len(widow_orphan_rules) > 0:
|
||||||
debug_print("KoboTouch:_modify_epub:Removing existing widows/orphans attribs")
|
debug_print("KoboTouch:_modify_epub:Removing existing widows/orphans attribs")
|
||||||
@ -1956,7 +1954,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def delete_via_sql(self, ContentID, ContentType):
|
def delete_via_sql(self, ContentID, ContentType):
|
||||||
imageId = super(KOBOTOUCH, self).delete_via_sql(ContentID, ContentType)
|
imageId = super(KOBOTOUCH, self).delete_via_sql(ContentID, ContentType)
|
||||||
|
|
||||||
@ -2247,7 +2244,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
self.dump_bookshelves(connection)
|
self.dump_bookshelves(connection)
|
||||||
|
|
||||||
|
|
||||||
debug_print('KoboTouch:update_device_database_collections - Finished ')
|
debug_print('KoboTouch:update_device_database_collections - Finished ')
|
||||||
|
|
||||||
def rebuild_collections(self, booklist, oncard):
|
def rebuild_collections(self, booklist, oncard):
|
||||||
@ -2292,7 +2288,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug_print('KoboTouch: FAILED to upload cover=%s Exception=%s'%(filepath, str(e)))
|
debug_print('KoboTouch: FAILED to upload cover=%s Exception=%s'%(filepath, str(e)))
|
||||||
|
|
||||||
|
|
||||||
def imageid_from_contentid(self, ContentID):
|
def imageid_from_contentid(self, ContentID):
|
||||||
ImageID = ContentID.replace('/', '_')
|
ImageID = ContentID.replace('/', '_')
|
||||||
ImageID = ImageID.replace(' ', '_')
|
ImageID = ImageID.replace(' ', '_')
|
||||||
@ -2300,7 +2295,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
ImageID = ImageID.replace('.', '_')
|
ImageID = ImageID.replace('.', '_')
|
||||||
return ImageID
|
return ImageID
|
||||||
|
|
||||||
|
|
||||||
def images_path(self, path):
|
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():
|
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/'
|
path_prefix = 'koboExtStorage/images/'
|
||||||
@ -2687,7 +2681,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
if show_debug:
|
if show_debug:
|
||||||
debug_print("KoboTouch:set_series - end")
|
debug_print("KoboTouch:set_series - end")
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def settings(cls):
|
def settings(cls):
|
||||||
opts = cls._config().parse()
|
opts = cls._config().parse()
|
||||||
@ -2710,7 +2703,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
opts.extra_customization = extra_customization
|
opts.extra_customization = extra_customization
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
|
|
||||||
def isAuraHD(self):
|
def isAuraHD(self):
|
||||||
return self.detected_device.idProduct in self.AURA_HD_PRODUCT_ID
|
return self.detected_device.idProduct in self.AURA_HD_PRODUCT_ID
|
||||||
def isGlo(self):
|
def isGlo(self):
|
||||||
@ -2736,7 +2728,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
self.__class__.gui_name = device_name
|
self.__class__.gui_name = device_name
|
||||||
return device_name
|
return device_name
|
||||||
|
|
||||||
|
|
||||||
def copying_covers(self):
|
def copying_covers(self):
|
||||||
opts = self.settings()
|
opts = self.settings()
|
||||||
return opts.extra_customization[self.OPT_UPLOAD_COVERS] or opts.extra_customization[self.OPT_KEEP_COVER_ASPECT_RATIO]
|
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()
|
opts = self.settings()
|
||||||
return opts.extra_customization[self.OPT_MODIFY_CSS]
|
return opts.extra_customization[self.OPT_MODIFY_CSS]
|
||||||
|
|
||||||
|
|
||||||
def supports_bookshelves(self):
|
def supports_bookshelves(self):
|
||||||
return self.dbversion >= self.min_supported_dbversion
|
return self.dbversion >= self.min_supported_dbversion
|
||||||
|
|
||||||
@ -2806,7 +2796,6 @@ class KOBOTOUCH(KOBO):
|
|||||||
# Supported database version
|
# Supported database version
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_debugging_title(cls, title):
|
def is_debugging_title(cls, title):
|
||||||
if not DEBUG:
|
if not DEBUG:
|
||||||
@ -2858,3 +2847,4 @@ class KOBOTOUCH(KOBO):
|
|||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
debug_print('KoboTouch:dump_bookshelves - end')
|
debug_print('KoboTouch:dump_bookshelves - end')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user