mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Few changes for silly path differences in Windows and darn tabs versus spaces
This commit is contained in:
parent
6ee7c8418d
commit
bb0c44693a
@ -24,34 +24,34 @@ class Book(MetaInformation):
|
|||||||
'uuid',
|
'uuid',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, mountpath, path, title, authors, mime, date, ContentType, ImageID, other=None):
|
def __init__(self, mountpath, path, title, authors, mime, date, ContentType, thumbnail_name, other=None):
|
||||||
|
|
||||||
MetaInformation.__init__(self, '')
|
MetaInformation.__init__(self, '')
|
||||||
self.device_collections = []
|
self.device_collections = []
|
||||||
|
|
||||||
self.title = title
|
self.title = title
|
||||||
if not authors:
|
if not authors:
|
||||||
self.authors = ['']
|
self.authors = ['']
|
||||||
else:
|
else:
|
||||||
self.authors = [authors]
|
self.authors = [authors]
|
||||||
self.mime = mime
|
self.mime = mime
|
||||||
self.path = path
|
self.path = path
|
||||||
try:
|
|
||||||
self.size = os.path.getsize(path)
|
|
||||||
except OSError:
|
|
||||||
self.size = 0
|
|
||||||
try:
|
try:
|
||||||
if ContentType == '6':
|
self.size = os.path.getsize(path)
|
||||||
self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
|
except OSError:
|
||||||
else:
|
self.size = 0
|
||||||
|
try:
|
||||||
|
if ContentType == '6':
|
||||||
|
self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
|
||||||
|
else:
|
||||||
self.datetime = time.gmtime(os.path.getctime(path))
|
self.datetime = time.gmtime(os.path.getctime(path))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.datetime = time.gmtime()
|
self.datetime = time.gmtime()
|
||||||
except OSError:
|
except OSError:
|
||||||
self.datetime = time.gmtime()
|
self.datetime = time.gmtime()
|
||||||
self.lpath = path
|
self.lpath = path
|
||||||
|
|
||||||
self.thumbnail = ImageWrapper(mountpath + '.kobo/images/' + ImageID + ' - iPhoneThumbnail.parsed')
|
self.thumbnail = ImageWrapper(thumbnail_name)
|
||||||
self.tags = []
|
self.tags = []
|
||||||
if other:
|
if other:
|
||||||
self.smart_update(other)
|
self.smart_update(other)
|
||||||
@ -108,5 +108,5 @@ class Book(MetaInformation):
|
|||||||
|
|
||||||
class ImageWrapper(object):
|
class ImageWrapper(object):
|
||||||
def __init__(self, image_path):
|
def __init__(self, image_path):
|
||||||
self.image_path = image_path
|
self.image_path = image_path
|
||||||
|
|
||||||
|
@ -82,14 +82,20 @@ class KOBO(USBMS):
|
|||||||
# if lpath.startswith(os.sep):
|
# if lpath.startswith(os.sep):
|
||||||
# lpath = lpath[len(os.sep):]
|
# lpath = lpath[len(os.sep):]
|
||||||
# lpath = lpath.replace('\\', '/')
|
# lpath = lpath.replace('\\', '/')
|
||||||
|
print "Filename: " + filename
|
||||||
|
filename = self.normalize_path(filename)
|
||||||
|
print "Normalized FileName: " + filename
|
||||||
|
|
||||||
idx = bl_cache.get(filename, None)
|
idx = bl_cache.get(filename, None)
|
||||||
if idx is not None:
|
if idx is not None:
|
||||||
bl[idx].thumbnail = ImageWrapper(mountpath + '.kobo/images/' + ImageID + ' - iPhoneThumbnail.parsed')
|
imagename = self.normalize_path(mountpath + '.kobo/images/' + ImageID + ' - iPhoneThumbnail.parsed')
|
||||||
|
print "Image name Normalized: " + imagename
|
||||||
|
bl[idx].thumbnail = ImageWrapper(imagename)
|
||||||
bl_cache[filename] = None
|
bl_cache[filename] = None
|
||||||
if ContentType != '6':
|
if ContentType != '6':
|
||||||
if self.update_metadata_item(bl[idx]):
|
if self.update_metadata_item(bl[idx]):
|
||||||
# print 'update_metadata_item returned true'
|
# print 'update_metadata_item returned true'
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
book = Book(mountpath, filename, title, authors, mime, date, ContentType, ImageID)
|
book = Book(mountpath, filename, title, authors, mime, date, ContentType, ImageID)
|
||||||
# print 'Update booklist'
|
# print 'Update booklist'
|
||||||
@ -103,21 +109,21 @@ class KOBO(USBMS):
|
|||||||
connection = sqlite.connect(self._main_prefix + '.kobo/KoboReader.sqlite')
|
connection = sqlite.connect(self._main_prefix + '.kobo/KoboReader.sqlite')
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
query = 'select count(distinct volumeId) from volume_shortcovers'
|
#query = 'select count(distinct volumeId) from volume_shortcovers'
|
||||||
cursor.execute(query)
|
#cursor.execute(query)
|
||||||
for row in (cursor):
|
#for row in (cursor):
|
||||||
numrows = row[0]
|
# numrows = row[0]
|
||||||
cursor.close()
|
#cursor.close()
|
||||||
|
|
||||||
query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
|
||||||
'ImageID from content where ContentID in (select distinct volumeId from volume_shortcovers)'
|
'ImageID from content where ContentID in (select distinct volumeId from volume_shortcovers)'
|
||||||
|
|
||||||
cursor.execute (query)
|
cursor.execute (query)
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
for i, row in enumerate(cursor):
|
for i, row in enumerate(cursor):
|
||||||
self.report_progress((i+1) / float(numrows), _('Getting list of books on device...'))
|
# self.report_progress((i+1) / float(numrows), _('Getting list of books on device...'))
|
||||||
|
|
||||||
filename = row[3]
|
filename = row[3]
|
||||||
if row[5] == "6":
|
if row[5] == "6":
|
||||||
@ -125,18 +131,18 @@ class KOBO(USBMS):
|
|||||||
mime = mime_type_ext(path_to_ext(row[3]))
|
mime = mime_type_ext(path_to_ext(row[3]))
|
||||||
|
|
||||||
if oncard != 'carda' and oncard != 'cardb':
|
if oncard != 'carda' and oncard != 'cardb':
|
||||||
if row[5] == '6':
|
if row[5] == '6':
|
||||||
# print "shortbook: " + filename
|
# print "shortbook: " + filename
|
||||||
changed = update_booklist(self._main_prefix, row[3], filename, row[0], row[1], mime, row[2], row[5], row[6])
|
changed = update_booklist(self._main_prefix, row[3], filename, row[0], row[1], mime, row[2], row[5], row[6])
|
||||||
|
if changed:
|
||||||
|
need_sync = True
|
||||||
|
else:
|
||||||
|
if filename.startswith("file:///mnt/onboard/"):
|
||||||
|
filename = filename.replace("file:///mnt/onboard/", self._main_prefix)
|
||||||
|
# print "Internal: " + filename
|
||||||
|
changed = update_booklist(self._main_prefix, row[3], filename, row[0], row[1], mime, row[2], row[5], row[6])
|
||||||
if changed:
|
if changed:
|
||||||
need_sync = True
|
need_sync = True
|
||||||
else:
|
|
||||||
if filename.startswith("file:///mnt/onboard/"):
|
|
||||||
filename = filename.replace("file:///mnt/onboard/", self._main_prefix)
|
|
||||||
# print "Internal: " + filename
|
|
||||||
changed = update_booklist(self._main_prefix, row[3], filename, row[0], row[1], mime, row[2], row[5], row[6])
|
|
||||||
if changed:
|
|
||||||
need_sync = True
|
|
||||||
elif oncard == 'carda':
|
elif oncard == 'carda':
|
||||||
if filename.startswith("file:///mnt/sd/"):
|
if filename.startswith("file:///mnt/sd/"):
|
||||||
filename = filename.replace("file:///mnt/sd/", self._card_a_prefix)
|
filename = filename.replace("file:///mnt/sd/", self._card_a_prefix)
|
||||||
@ -145,14 +151,14 @@ class KOBO(USBMS):
|
|||||||
if changed:
|
if changed:
|
||||||
need_sync = True
|
need_sync = True
|
||||||
else:
|
else:
|
||||||
print "Add card b support"
|
print "Add card b support"
|
||||||
|
|
||||||
#FIXME - NOT NEEDED flist.append({'filename': filename, 'path':row[3]})
|
#FIXME - NOT NEEDED flist.append({'filename': filename, 'path':row[3]})
|
||||||
#bl.append(book)
|
#bl.append(book)
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
# Remove books that are no longer in the filesystem. Cache contains
|
# Remove books that are no longer in the filesystem. Cache contains
|
||||||
# indices into the booklist if book not in filesystem, None otherwise
|
# indices into the booklist if book not in filesystem, None otherwise
|
||||||
# Do the operation in reverse order so indices remain valid
|
# Do the operation in reverse order so indices remain valid
|
||||||
@ -185,48 +191,56 @@ class KOBO(USBMS):
|
|||||||
t = (ContentID,)
|
t = (ContentID,)
|
||||||
cursor.execute('select ImageID from content where ContentID = ?', t)
|
cursor.execute('select ImageID from content where ContentID = ?', t)
|
||||||
|
|
||||||
|
ImageID = None
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
# First get the ImageID to delete the images
|
# First get the ImageID to delete the images
|
||||||
ImageID = row[0]
|
ImageID = row[0]
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
cursor = connection.cursor()
|
if ImageID != None:
|
||||||
if ContentType == 6:
|
cursor = connection.cursor()
|
||||||
# Delete the shortcover_pages first
|
if ContentType == 6:
|
||||||
cursor.execute('delete from shortcover_page where shortcoverid in (select ContentID from content where BookID = ?)', t)
|
# 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)
|
cursor.execute('delete from volume_shortcovers where volumeid = ?', t)
|
||||||
|
|
||||||
# Delete the chapters associated with the book next
|
# Delete the chapters associated with the book next
|
||||||
t = (ContentID,ContentID,)
|
t = (ContentID,ContentID,)
|
||||||
cursor.execute('delete from content where BookID = ? or ContentID = ?', t)
|
cursor.execute('delete from content where BookID = ? or ContentID = ?', t)
|
||||||
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
else:
|
||||||
|
print "Error condition ImageID was not found"
|
||||||
|
print "You likely tried to delete a book that the kobo has not yet added to the database"
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
connection.close()
|
connection.close()
|
||||||
# If all this succeeds we need to delete the images files via the ImageID
|
# If all this succeeds we need to delete the images files via the ImageID
|
||||||
return ImageID
|
return ImageID
|
||||||
|
|
||||||
def delete_images(self, ImageID):
|
def delete_images(self, ImageID):
|
||||||
path_prefix = '.kobo/images/'
|
if ImageID == None:
|
||||||
path = self._main_prefix + path_prefix + ImageID
|
path_prefix = '.kobo/images/'
|
||||||
|
path = self._main_prefix + path_prefix + ImageID
|
||||||
|
|
||||||
file_endings = (' - iPhoneThumbnail.parsed', ' - bbMediumGridList.parsed', ' - NickelBookCover.parsed',)
|
file_endings = (' - iPhoneThumbnail.parsed', ' - bbMediumGridList.parsed', ' - NickelBookCover.parsed',)
|
||||||
|
|
||||||
for ending in file_endings:
|
for ending in file_endings:
|
||||||
fpath = path + ending
|
fpath = path + ending
|
||||||
fpath = self.normalize_path(fpath)
|
fpath = self.normalize_path(fpath)
|
||||||
|
|
||||||
if os.path.exists(fpath):
|
if os.path.exists(fpath):
|
||||||
# print 'Image File Exists: ' + fpath
|
# print 'Image File Exists: ' + fpath
|
||||||
os.unlink(fpath)
|
os.unlink(fpath)
|
||||||
|
|
||||||
def delete_books(self, paths, end_session=True):
|
def delete_books(self, paths, end_session=True):
|
||||||
for i, path in enumerate(paths):
|
for i, path in enumerate(paths):
|
||||||
self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
|
self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
|
||||||
path = self.normalize_path(path)
|
path = self.normalize_path(path)
|
||||||
|
print "Delete file normalized path: " + path
|
||||||
extension = os.path.splitext(path)[1]
|
extension = os.path.splitext(path)[1]
|
||||||
|
|
||||||
if extension == '.kobo':
|
if extension == '.kobo':
|
||||||
@ -238,7 +252,7 @@ class KOBO(USBMS):
|
|||||||
ContentID = ContentID.replace(self._main_prefix, '')
|
ContentID = ContentID.replace(self._main_prefix, '')
|
||||||
if self._card_a_prefix is not None:
|
if self._card_a_prefix is not None:
|
||||||
ContentID = ContentID.replace(self._card_a_prefix, '')
|
ContentID = ContentID.replace(self._card_a_prefix, '')
|
||||||
|
ContentID = ContentID.replace("\\", '/')
|
||||||
ImageID = self.delete_via_sql(ContentID, 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)
|
self.delete_images(ImageID)
|
||||||
@ -250,6 +264,7 @@ class KOBO(USBMS):
|
|||||||
ContentID = ContentID.replace(self._main_prefix, "file:///mnt/onboard/")
|
ContentID = ContentID.replace(self._main_prefix, "file:///mnt/onboard/")
|
||||||
if self._card_a_prefix is not None:
|
if self._card_a_prefix is not None:
|
||||||
ContentID = ContentID.replace(self._card_a_prefix, "file:///mnt/sd/")
|
ContentID = ContentID.replace(self._card_a_prefix, "file:///mnt/sd/")
|
||||||
|
ContentID = ContentID.replace("\\", '/')
|
||||||
# print "ContentID: " + ContentID
|
# print "ContentID: " + ContentID
|
||||||
ImageID = self.delete_via_sql(ContentID, 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
|
||||||
@ -313,17 +328,17 @@ class KOBO(USBMS):
|
|||||||
prints('in add_books_to_metadata. Prefix is None!', path,
|
prints('in add_books_to_metadata. Prefix is None!', path,
|
||||||
self._main_prefix)
|
self._main_prefix)
|
||||||
continue
|
continue
|
||||||
|
print "Add book to metatdata: "
|
||||||
|
print "prefix: " + prefix
|
||||||
lpath = path.partition(prefix)[2]
|
lpath = path.partition(prefix)[2]
|
||||||
if lpath.startswith('/') or lpath.startswith('\\'):
|
if lpath.startswith('/') or lpath.startswith('\\'):
|
||||||
lpath = lpath[1:]
|
lpath = lpath[1:]
|
||||||
|
print "path: " + lpath
|
||||||
#book = self.book_class(prefix, lpath, other=info)
|
#book = self.book_class(prefix, lpath, other=info)
|
||||||
book = Book(prefix, lpath, '', '', '', '', '', '', other=info)
|
lpath = self.normalize_path(prefix + lpath)
|
||||||
|
book = Book(prefix, lpath, '', '', '', '', '', '', other=info)
|
||||||
if book.size is None:
|
if book.size is None:
|
||||||
book.size = os.stat(self.normalize_path(path)).st_size
|
book.size = os.stat(self.normalize_path(path)).st_size
|
||||||
booklists[blist].add_book(book, replace_metadata=True)
|
booklists[blist].add_book(book, replace_metadata=True)
|
||||||
self.report_progress(1.0, _('Adding books to device metadata listing...'))
|
self.report_progress(1.0, _('Adding books to device metadata listing...'))
|
||||||
|
|
||||||
#class ImageWrapper(object):
|
|
||||||
# def __init__(self, image_path):
|
|
||||||
# self.image_path = image_path
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user