From bcd1d79352d584b33c4d09cb755712aadd3f1139 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 11 Oct 2010 10:42:29 +0100 Subject: [PATCH] Fix #7124, collections becoming unsorted when using manual management --- src/calibre/devices/usbms/books.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index a267d18584..30d25781cf 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -124,7 +124,6 @@ class CollectionsBookList(BookList): collections = {} # This map of sets is used to avoid linear searches when testing for # book equality - collections_lpaths = {} for book in self: # Make sure we can identify this book via the lpath lpath = getattr(book, 'lpath', None) @@ -198,20 +197,22 @@ class CollectionsBookList(BookList): cat_name = category if cat_name not in collections: - collections[cat_name] = [] - collections_lpaths[cat_name] = set() - if lpath in collections_lpaths[cat_name]: - continue - collections_lpaths[cat_name].add(lpath) + collections[cat_name] = {} if is_series: - collections[cat_name].append( - (book, book.get(attr+'_index', sys.maxint))) + if doing_dc: + collections[cat_name][lpath] = \ + (book, book.get('series_index', sys.maxint)) + else: + collections[cat_name][lpath] = \ + (book, book.get(attr+'_index', sys.maxint)) else: - collections[cat_name].append( - (book, book.get('title_sort', 'zzzz'))) + if lpath not in collections[cat_name]: + collections[cat_name][lpath] = \ + (book, book.get('title_sort', 'zzzz')) # Sort collections result = {} - for category, books in collections.items(): + for category, lpaths in collections.items(): + books = lpaths.values() books.sort(cmp=lambda x,y:cmp(x[1], y[1])) result[category] = [x[0] for x in books] return result