Additional clean up and conver to using path and lpath correctly - more review of lpath and path needed

This commit is contained in:
Timothy Legge 2010-06-18 22:37:16 -03:00
parent 724c0aac3d
commit da83447900
2 changed files with 31 additions and 22 deletions

View File

@ -24,32 +24,37 @@ class Book(MetaInformation):
'uuid', 'uuid',
] ]
def __init__(self, mountpath, path, title, authors, mime, date, ContentType, thumbnail_name, other=None): def __init__(self, prefix, lpath, title, authors, mime, date, ContentType, thumbnail_name, other=None):
MetaInformation.__init__(self, '') MetaInformation.__init__(self, '')
self.device_collections = [] self.device_collections = []
self.path = os.path.join(prefix, lpath)
if os.sep == '\\':
self.path = self.path.replace('/', '\\')
self.lpath = lpath.replace('\\', '/')
else:
self.lpath = lpath
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
try: try:
self.size = os.path.getsize(path) self.size = os.path.getsize(self.path)
except OSError: except OSError:
self.size = 0 self.size = 0
try: try:
if ContentType == '6': if ContentType == '6':
self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f") self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
else: else:
self.datetime = time.gmtime(os.path.getctime(path)) self.datetime = time.gmtime(os.path.getctime(self.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.thumbnail = ImageWrapper(thumbnail_name) self.thumbnail = ImageWrapper(thumbnail_name)
self.tags = [] self.tags = []

View File

@ -22,7 +22,7 @@ class KOBO(USBMS):
gui_name = 'Kobo Reader' gui_name = 'Kobo Reader'
description = _('Communicate with the Kobo Reader') description = _('Communicate with the Kobo Reader')
author = 'Timothy Legge and Kovid Goyal' author = 'Timothy Legge and Kovid Goyal'
version = (1, 0, 1) version = (1, 0, 2)
supported_platforms = ['windows', 'osx', 'linux'] supported_platforms = ['windows', 'osx', 'linux']
@ -75,34 +75,35 @@ class KOBO(USBMS):
for idx,b in enumerate(bl): for idx,b in enumerate(bl):
bl_cache[b.lpath] = idx bl_cache[b.lpath] = idx
def update_booklist(mountpath, filename, title, authors, mime, date, ContentType, ImageID): def update_booklist(prefix, path, title, authors, mime, date, ContentType, ImageID):
changed = False changed = False
# if path_to_ext(filename) in self.FORMATS: # if path_to_ext(path) in self.FORMATS:
try: try:
# lpath = os.path.join(path, filename).partition(self.normalize_path(prefix))[2] lpath = path.partition(self.normalize_path(prefix))[2]
# 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 # print "LPATH: " + lpath
filename = self.normalize_path(filename)
# print "Normalized FileName: " + filename
idx = bl_cache.get(filename, None) path = self.normalize_path(path)
# print "Normalized FileName: " + path
idx = bl_cache.get(lpath, None)
if idx is not None: if idx is not None:
imagename = self.normalize_path(mountpath + '.kobo/images/' + ImageID + ' - iPhoneThumbnail.parsed') imagename = self.normalize_path(prefix + '.kobo/images/' + ImageID + ' - iPhoneThumbnail.parsed')
#print "Image name Normalized: " + imagename #print "Image name Normalized: " + imagename
bl[idx].thumbnail = ImageWrapper(imagename) bl[idx].thumbnail = ImageWrapper(imagename)
bl_cache[filename] = None bl_cache[lpath] = 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(prefix, lpath, title, authors, mime, date, ContentType, ImageID)
# print 'Update booklist' # print 'Update booklist'
if bl.add_book(book, replace_metadata=False): if bl.add_book(book, replace_metadata=False):
changed = True changed = True
except: # Probably a filename encoding error except: # Probably a path encoding error
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return changed return changed
@ -129,7 +130,7 @@ 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':
# print "shortbook: " + filename # print "shortbook: " + path
changed = update_booklist(self._main_prefix, path, row[0], row[1], mime, row[2], row[5], row[6]) changed = update_booklist(self._main_prefix, path, row[0], row[1], mime, row[2], row[5], row[6])
elif oncard == 'carda': elif oncard == 'carda':
changed = update_booklist(self._card_a_prefix, path, row[0], row[1], mime, row[2], row[5], row[6]) changed = update_booklist(self._card_a_prefix, path, row[0], row[1], mime, row[2], row[5], row[6])
@ -334,7 +335,10 @@ class KOBO(USBMS):
if oncard != 'carda' and oncard != 'cardb': if oncard != 'carda' and oncard != 'cardb':
if ContentType == "6": if ContentType == "6":
path = path + '.kobo' # This is a hack as the kobo files do not exist
# but the path is required to make a unique id
# for calibre's reference
path = self._main_prefix + os.sep + path + '.kobo'
else: else:
if path.startswith("file:///mnt/onboard/"): if path.startswith("file:///mnt/onboard/"):
path = path.replace("file:///mnt/onboard/", self._main_prefix) path = path.replace("file:///mnt/onboard/", self._main_prefix)