From d0986bbe8ad24d82feab3b2415294a1a88fb4bb6 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Jan 2009 21:13:00 -0500 Subject: [PATCH] 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. --- src/calibre/devices/usbms/books.py | 3 +++ src/calibre/devices/usbms/driver.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 3943ef94f4..fffed41549 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -18,6 +18,9 @@ class Book(object): self.thumbnail = None self.tags = [] + def __eq__(self, other): + return self.path == other.path + @apply def title_sorter(): doc = '''String to sort the title. If absent, title is returned''' diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index db527c04ea..7529890470 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -109,7 +109,7 @@ class USBMS(Device): if not os.path.exists(newpath): os.makedirs(newpath) - filepath = os.path.join(newpath, names.next()) + filepath = os.path.join(newpath, names.next()) paths.append(filepath) if hasattr(infile, 'read'): @@ -132,7 +132,10 @@ class USBMS(Device): on_card = 1 if location[1] else 0 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): for path in paths: