Few changes for silly path differences in Windows and darn tabs versus spaces

This commit is contained in:
Timothy Legge 2010-06-08 19:38:27 -03:00
parent 6ee7c8418d
commit bb0c44693a
2 changed files with 83 additions and 68 deletions

View File

@ -24,7 +24,7 @@ class Book(MetaInformation):
'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, '')
self.device_collections = []
@ -51,7 +51,7 @@ class Book(MetaInformation):
self.datetime = time.gmtime()
self.lpath = path
self.thumbnail = ImageWrapper(mountpath + '.kobo/images/' + ImageID + ' - iPhoneThumbnail.parsed')
self.thumbnail = ImageWrapper(thumbnail_name)
self.tags = []
if other:
self.smart_update(other)

View File

@ -82,9 +82,15 @@ class KOBO(USBMS):
# if lpath.startswith(os.sep):
# lpath = lpath[len(os.sep):]
# lpath = lpath.replace('\\', '/')
print "Filename: " + filename
filename = self.normalize_path(filename)
print "Normalized FileName: " + filename
idx = bl_cache.get(filename, 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
if ContentType != '6':
if self.update_metadata_item(bl[idx]):
@ -103,11 +109,11 @@ class KOBO(USBMS):
connection = sqlite.connect(self._main_prefix + '.kobo/KoboReader.sqlite')
cursor = connection.cursor()
query = 'select count(distinct volumeId) from volume_shortcovers'
cursor.execute(query)
for row in (cursor):
numrows = row[0]
cursor.close()
#query = 'select count(distinct volumeId) from volume_shortcovers'
#cursor.execute(query)
#for row in (cursor):
# numrows = row[0]
#cursor.close()
query= 'select Title, Attribution, DateCreated, ContentID, MimeType, ContentType, ' \
'ImageID from content where ContentID in (select distinct volumeId from volume_shortcovers)'
@ -117,7 +123,7 @@ class KOBO(USBMS):
changed = False
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]
if row[5] == "6":
@ -185,11 +191,13 @@ class KOBO(USBMS):
t = (ContentID,)
cursor.execute('select ImageID from content where ContentID = ?', t)
ImageID = None
for row in cursor:
# First get the ImageID to delete the images
ImageID = row[0]
cursor.close()
if ImageID != None:
cursor = connection.cursor()
if ContentType == 6:
# Delete the shortcover_pages first
@ -205,11 +213,16 @@ class KOBO(USBMS):
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"
connection.close()
# If all this succeeds we need to delete the images files via the ImageID
return ImageID
def delete_images(self, ImageID):
if ImageID == None:
path_prefix = '.kobo/images/'
path = self._main_prefix + path_prefix + ImageID
@ -227,6 +240,7 @@ class KOBO(USBMS):
for i, path in enumerate(paths):
self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
path = self.normalize_path(path)
print "Delete file normalized path: " + path
extension = os.path.splitext(path)[1]
if extension == '.kobo':
@ -238,7 +252,7 @@ class KOBO(USBMS):
ContentID = ContentID.replace(self._main_prefix, '')
if self._card_a_prefix is not None:
ContentID = ContentID.replace(self._card_a_prefix, '')
ContentID = ContentID.replace("\\", '/')
ImageID = self.delete_via_sql(ContentID, ContentType)
#print " We would now delete the Images for" + ImageID
self.delete_images(ImageID)
@ -250,6 +264,7 @@ class KOBO(USBMS):
ContentID = ContentID.replace(self._main_prefix, "file:///mnt/onboard/")
if self._card_a_prefix is not None:
ContentID = ContentID.replace(self._card_a_prefix, "file:///mnt/sd/")
ContentID = ContentID.replace("\\", '/')
# print "ContentID: " + ContentID
ImageID = self.delete_via_sql(ContentID, ContentType)
#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,
self._main_prefix)
continue
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
#book = self.book_class(prefix, lpath, other=info)
lpath = self.normalize_path(prefix + lpath)
book = Book(prefix, lpath, '', '', '', '', '', '', other=info)
if book.size is None:
book.size = os.stat(self.normalize_path(path)).st_size
booklists[blist].add_book(book, replace_metadata=True)
self.report_progress(1.0, _('Adding books to device metadata listing...'))
#class ImageWrapper(object):
# def __init__(self, image_path):
# self.image_path = image_path