From ecbea8b0e22b507d88db5cfab997d38031a46196 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 12 Jul 2013 18:04:27 +0530 Subject: [PATCH] More API --- src/calibre/db/legacy.py | 16 ++++++++++++++++ src/calibre/db/tests/legacy.py | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 97be03fb19..a4dd30a88c 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -109,6 +109,9 @@ class LibraryDatabase(object): self.last_update_check = self.last_modified() self.book_on_device_func = None + # Cleaning is not required anymore + self.clean = self.clean_custom = MT(lambda self:None) + self.clean_standard_field = MT(lambda self, field, commit=False:None) def close(self): self.backend.close() @@ -352,6 +355,19 @@ class LibraryDatabase(object): def set_book_on_device_func(self, func): self.book_on_device_func = func + def books_in_series(self, series_id): + with self.new_api.read_lock: + book_ids = self.new_api._books_for_field('series', series_id) + ff = self.new_api._field_for + return sorted(book_ids, key=lambda x:ff('series_index', x)) + + def books_in_series_of(self, index, index_is_id=False): + book_id = index if index_is_id else self.data.index_to_id(index) + series_ids = self.new_api.field_ids_for('series', book_id) + if not series_ids: + return [] + return self.books_in_series(series_ids[0]) + # Private interface {{{ def __iter__(self): diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index e5a8a8e7b5..5c26e50ae5 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -176,6 +176,7 @@ class LegacyTest(BaseTest): 'author_sort_from_book':[(0,), (1,), (2,)], 'authors_with_sort_strings':[(0,), (1,), (2,)], 'book_on_device_string':[(1,), (2,), (3,)], + 'books_in_series_of':[(0,), (1,), (2,)], }.iteritems(): for a in args: fmt = lambda x: x @@ -265,6 +266,8 @@ class LegacyTest(BaseTest): 'author_id', # replaced by get_author_id 'books_for_author', # broken 'books_in_old_database', # unused + 'clean_user_categories', # internal API + 'cleanup_tags', # internal API } SKIP_ARGSPEC = { '__init__', 'get_next_series_num_for', 'has_book', 'author_sort_from_authors',