From b04faf70c2378c3569a4d1cf010da3d57a707c42 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 27 Aug 2010 08:22:08 +0100 Subject: [PATCH] Make Kobo driver use new metadata framework --- src/calibre/devices/kobo/books.py | 80 ++---------------------------- src/calibre/devices/kobo/driver.py | 2 +- 2 files changed, 5 insertions(+), 77 deletions(-) diff --git a/src/calibre/devices/kobo/books.py b/src/calibre/devices/kobo/books.py index f0cf7c3763..1c3d05ea12 100644 --- a/src/calibre/devices/kobo/books.py +++ b/src/calibre/devices/kobo/books.py @@ -4,37 +4,15 @@ __copyright__ = '2010, Timothy Legge ' ''' import os -import re import time -from calibre.ebooks.metadata.book.base import Metadata -from calibre.constants import filesystem_encoding, preferred_encoding -from calibre import isbytestring +from calibre.devices.usbms.books import Book as Book_ -class Book(Metadata): - - BOOK_ATTRS = ['lpath', 'size', 'mime', 'device_collections', '_new_book'] - - JSON_ATTRS = [ - 'lpath', 'title', 'authors', 'mime', 'size', 'tags', 'author_sort', - 'title_sort', 'comments', 'category', 'publisher', 'series', - 'series_index', 'rating', 'isbn', 'language', 'application_id', - 'book_producer', 'lccn', 'lcc', 'ddc', 'rights', 'publication_type', - 'uuid', 'device_collections', - ] +class Book(Book_): def __init__(self, prefix, lpath, title, authors, mime, date, ContentType, thumbnail_name, other=None): - Metadata.__init__(self, '') - self.device_collections = [] - self._new_book = False - - self.path = os.path.join(prefix, lpath) - if os.sep == '\\': - self.path = self.path.replace('/', '\\') - self.lpath = lpath.replace('\\', '/') - else: - self.lpath = lpath + Book_.__init__(self, prefix, lpath) self.title = title if not authors: @@ -59,57 +37,7 @@ class Book(Metadata): if other: self.smart_update(other) - def __eq__(self, other): - return self.path == getattr(other, 'path', None) - - @dynamic_property - def db_id(self): - doc = '''The database id in the application database that this file corresponds to''' - def fget(self): - match = re.search(r'_(\d+)$', self.lpath.rpartition('.')[0]) - if match: - return int(match.group(1)) - return None - return property(fget=fget, doc=doc) - - @dynamic_property - def title_sorter(self): - doc = '''String to sort the title. If absent, title is returned''' - def fget(self): - return re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', self.title).rstrip() - return property(doc=doc, fget=fget) - - @dynamic_property - def thumbnail(self): - return None - - def smart_update(self, other, replace_metadata=False): - ''' - Merge the information in C{other} into self. In case of conflicts, the information - in C{other} takes precedence, unless the information in C{other} is NULL. - ''' - - Metadata.smart_update(self, other) - - for attr in self.BOOK_ATTRS: - if hasattr(other, attr): - val = getattr(other, attr, None) - setattr(self, attr, val) - - def to_json(self): - json = {} - for attr in self.JSON_ATTRS: - val = getattr(self, attr) - if isbytestring(val): - enc = filesystem_encoding if attr == 'lpath' else preferred_encoding - val = val.decode(enc, 'replace') - elif isinstance(val, (list, tuple)): - val = [x.decode(preferred_encoding, 'replace') if - isbytestring(x) else x for x in val] - json[attr] = val - return json - class ImageWrapper(object): def __init__(self, image_path): - self.image_path = image_path + self.image_path = image_path diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 35fceb80f7..5f939a4498 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -132,7 +132,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...')) path = self.path_from_contentid(row[3], row[5], oncard) mime = mime_type_ext(path_to_ext(row[3]))