Do not add books to the list of books on device if they are already in the list. Fixes book showing up multiple times if it it sent to the device multiple times. Only one istance of the book will be on the device in this case.

This commit is contained in:
John Schember 2009-01-20 21:13:00 -05:00
parent 02e4e537e4
commit d0986bbe8a
2 changed files with 8 additions and 2 deletions

View File

@ -18,6 +18,9 @@ class Book(object):
self.thumbnail = None self.thumbnail = None
self.tags = [] self.tags = []
def __eq__(self, other):
return self.path == other.path
@apply @apply
def title_sorter(): def title_sorter():
doc = '''String to sort the title. If absent, title is returned''' doc = '''String to sort the title. If absent, title is returned'''

View File

@ -109,7 +109,7 @@ class USBMS(Device):
if not os.path.exists(newpath): if not os.path.exists(newpath):
os.makedirs(newpath) os.makedirs(newpath)
filepath = os.path.join(newpath, names.next()) filepath = os.path.join(newpath, names.next())
paths.append(filepath) paths.append(filepath)
if hasattr(infile, 'read'): if hasattr(infile, 'read'):
@ -132,7 +132,10 @@ class USBMS(Device):
on_card = 1 if location[1] else 0 on_card = 1 if location[1] else 0
title, author, mime = cls.extract_book_metadata_by_filename(os.path.basename(path)) title, author, mime = cls.extract_book_metadata_by_filename(os.path.basename(path))
booklists[on_card].append(Book(path, title, author, mime)) book = Book(path, title, author, mime)
if not book in booklists[on_card]:
booklists[on_card].append(book)
def delete_books(self, paths, end_session=True): def delete_books(self, paths, end_session=True):
for path in paths: for path in paths: