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,7 +24,7 @@ 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 = []
|
||||||
@ -51,7 +51,7 @@ class Book(MetaInformation):
|
|||||||
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)
|
||||||
|
@ -82,9 +82,15 @@ 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]):
|
||||||
@ -103,11 +109,11 @@ 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)'
|
||||||
@ -117,7 +123,7 @@ class KOBO(USBMS):
|
|||||||
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":
|
||||||
@ -185,11 +191,13 @@ 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()
|
||||||
|
|
||||||
|
if ImageID != None:
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
if ContentType == 6:
|
if ContentType == 6:
|
||||||
# Delete the shortcover_pages first
|
# Delete the shortcover_pages first
|
||||||
@ -205,11 +213,16 @@ class KOBO(USBMS):
|
|||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
cursor.close()
|
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"
|
||||||
|
|
||||||
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):
|
||||||
|
if ImageID == None:
|
||||||
path_prefix = '.kobo/images/'
|
path_prefix = '.kobo/images/'
|
||||||
path = self._main_prefix + path_prefix + ImageID
|
path = self._main_prefix + path_prefix + ImageID
|
||||||
|
|
||||||
@ -227,6 +240,7 @@ class KOBO(USBMS):
|
|||||||
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)
|
||||||
|
lpath = self.normalize_path(prefix + lpath)
|
||||||
book = Book(prefix, lpath, '', '', '', '', '', '', other=info)
|
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