Fix problem where the _new_book indication was being lost

This commit is contained in:
Charles Haley 2010-10-05 06:23:39 +01:00
parent 0b655b46fa
commit effa69add2
4 changed files with 14 additions and 7 deletions

View File

@ -325,8 +325,9 @@ class KOBO(USBMS):
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
book._new_book = True # Must be before add_book b = booklists[blist].add_book(book, replace_metadata=True)
booklists[blist].add_book(book, replace_metadata=True) if b:
b._new_book = True
self.report_progress(1.0, _('Adding books to device metadata listing...')) self.report_progress(1.0, _('Adding books to device metadata listing...'))
def contentid_from_path(self, path, ContentType): def contentid_from_path(self, path, ContentType):

View File

@ -362,6 +362,7 @@ class XMLCache(object):
if plugboard is not None: if plugboard is not None:
newmi = book.deepcopy_metadata() newmi = book.deepcopy_metadata()
newmi.template_to_attribute(book, plugboard) newmi.template_to_attribute(book, plugboard)
newmi.set('_new_book', getattr(book, '_new_book', False))
else: else:
newmi = book newmi = book
(gtz_count, ltz_count, use_tz_var) = \ (gtz_count, ltz_count, use_tz_var) = \

View File

@ -71,17 +71,21 @@ class BookList(_BookList):
return False return False
def add_book(self, book, replace_metadata): def add_book(self, book, replace_metadata):
'''
Add the book to the booklist, if needed. Return None if the book is
already there and not updated, otherwise return the book.
'''
try: try:
b = self.index(book) b = self.index(book)
except (ValueError, IndexError): except (ValueError, IndexError):
b = None b = None
if b is None: if b is None:
self.append(book) self.append(book)
return True return book
if replace_metadata: if replace_metadata:
self[b].smart_update(book, replace_metadata=True) self[b].smart_update(book, replace_metadata=True)
return True return self[b]
return False return None
def remove_book(self, book): def remove_book(self, book):
self.remove(book) self.remove(book)

View File

@ -242,8 +242,9 @@ class USBMS(CLI, Device):
book = self.book_class(prefix, lpath, other=info) book = self.book_class(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
book._new_book = True # Must be before add_book b = booklists[blist].add_book(book, replace_metadata=True)
booklists[blist].add_book(book, replace_metadata=True) if b:
b._new_book = True
self.report_progress(1.0, _('Adding books to device metadata listing...')) self.report_progress(1.0, _('Adding books to device metadata listing...'))
debug_print('USBMS: finished adding metadata') debug_print('USBMS: finished adding metadata')