Various fixes needed for the new metainformation based drivers

This commit is contained in:
Kovid Goyal 2010-01-01 10:51:00 -07:00
parent 9a28d7017f
commit c065a4d8fa
5 changed files with 31 additions and 27 deletions

View file

@ -48,9 +48,9 @@ class CYBOOKG3(USBMS):
def upload_cover(self, path, filename, metadata):
coverdata = getattr(metadata, 'thumbnail', None)
if coverdata:
if coverdata and coverdata[2]:
with open('%s_6090.t2b' % os.path.join(path, filename), 'wb') as t2bfile:
t2b.write_t2b(t2bfile, coverdata)
t2b.write_t2b(t2bfile, coverdata[2])
@classmethod
def can_handle(cls, device_info, debug=False):

View file

@ -276,7 +276,9 @@ def upload_books(self, files, names, on_card=None, end_session=True,
The idea is to use the metadata to determine where on the device to
put the book. len(metadata) == len(files). Apart from the regular
cover_data, there may also be a thumbnail attribute, which should
be used in preference.
be used in preference. The thumbnail attribute is of the form
(width, height, cover_data as jpeg). In addition the MetaInformation
objects can have a tag_order attribute.
'''
raise NotImplementedError()
@ -286,17 +288,8 @@ def add_books_to_metadata(cls, locations, metadata, booklists):
Add locations to the booklists. This function must not communicate with
the device.
@param locations: Result of a call to L{upload_books}
@param metadata: List of dictionaries. Each dictionary must have the
keys C{title}, C{authors}, C{author_sort}, C{cover}, C{tags}.
The value of the C{cover}
element can be None or a three element tuple (width, height, data)
where data is the image data in JPEG format as a string. C{tags} must be
a possibly empty list of strings. C{authors} must be a string.
C{author_sort} may be None. It is upto the driver to decide whether to
use C{author_sort} or not.
The dictionary can also have an optional key "tag order" which should be
another dictionary that maps tag names to lists of book ids. The ids are
ids from the book database.
@param metadata: List of MetaInformation objects, same as for
:method:`upload_books`.
@param booklists: A tuple containing the result of calls to
(L{books}(oncard=None), L{books}(oncard='carda'),
L{books}(oncard='cardb')).

View file

@ -54,8 +54,8 @@ def upload_cover(self, path, filename, metadata):
coverdata = getattr(metadata, 'thumbnail', None)
if coverdata:
cover = Image.open(cStringIO.StringIO(coverdata))
if coverdata and coverdata[2]:
cover = Image.open(cStringIO.StringIO(coverdata[2]))
else:
coverdata = open(I('library.png'), 'rb').read()

View file

@ -180,7 +180,7 @@ def book_by_path(self, path):
return child
return None
def add_book(self, info, name, size, ctime):
def add_book(self, mi, name, size, ctime):
""" Add a node into the DOM tree, representing a book """
book = self.book_by_path(name)
if book is not None:
@ -194,9 +194,9 @@ def add_book(self, info, name, size, ctime):
except:
sourceid = '1'
attrs = {
"title" : info["title"],
'titleSorter' : sortable_title(info['title']),
"author" : info["authors"] if info['authors'] else _('Unknown'),
"title" : mi.title,
'titleSorter' : sortable_title(mi.title),
"author" : mi.format_authors() if mi.format_authors() else _('Unknown'),
"page":"0", "part":"0", "scale":"0", \
"sourceid":sourceid, "id":str(cid), "date":"", \
"mime":mime, "path":name, "size":str(size)
@ -205,8 +205,8 @@ def add_book(self, info, name, size, ctime):
node.setAttributeNode(self.document.createAttribute(attr))
node.setAttribute(attr, attrs[attr])
try:
w, h, data = info["cover"]
except TypeError:
w, h, data = mi.thumbnail
except:
w, h, data = None, None, None
if data:
@ -221,10 +221,15 @@ def add_book(self, info, name, size, ctime):
book = Book(node, self.mountpath, [], prefix=self.prefix)
book.datetime = ctime
self.append(book)
if info.has_key('tags'):
if info.has_key('tag order'):
self.tag_order.update(info['tag order'])
self.set_tags(book, info['tags'])
tags = []
if mi.tags:
tags.extend(mi.tags)
if mi.series:
tags.append(mi.series)
if tags:
if hasattr(mi, 'tag_order'):
self.tag_order.update(mi.tag_order)
self.set_tags(book, tags)
def _delete_book(self, node):
nid = node.getAttribute('id')

View file

@ -400,7 +400,13 @@ def get_book_info(self, index):
return data
def metadata_for(self, ids):
return [self.db.get_metadata(id, index_is_id=True) for id in ids]
ans = []
for id in ids:
mi = self.db.get_metadata(id, index_is_id=True)
if mi.series is not None:
mi.tag_order = self.db.books_in_series_of(id, index_is_id=True)
ans.append(mi)
return ans
def get_metadata(self, rows, rows_are_ids=False, full_metadata=False):
metadata, _full_metadata = [], []