From a49b518cde782a8efc43c39aed998d1d5f6fafde Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 16 Jul 2013 17:58:22 +0530 Subject: [PATCH] cover_last_modified() --- src/calibre/db/backend.py | 7 +++++++ src/calibre/db/cache.py | 8 ++++++++ src/calibre/db/legacy.py | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 2c4dfb8395..1f561980bd 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -963,6 +963,13 @@ class DB(object): import traceback traceback.print_exc() + def cover_last_modified(self, path): + path = os.path.abspath(os.path.join(self.library_path, path, 'cover.jpg')) + try: + return utcfromtimestamp(os.stat(path).st_mtime) + except EnvironmentError: + pass # Cover doesn't exist + def copy_cover_to(self, path, dest, windows_atomic_move=None, use_hardlink=False): path = os.path.abspath(os.path.join(self.library_path, path, 'cover.jpg')) if windows_atomic_move is not None: diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 6564a9a9a2..e7c3114f0d 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -526,6 +526,14 @@ class Cache(object): ret = i return ret + @read_api + def cover_last_modified(self, book_id): + try: + path = self._field_for('path', book_id).replace('/', os.sep) + except AttributeError: + return + return self.backend.cover_last_modified(path) + @read_api def copy_cover_to(self, book_id, dest, use_hardlink=False): ''' diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index f13e8107df..a6d7f22989 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -290,6 +290,10 @@ class LibraryDatabase(object): mi = self.new_api.get_metadata(book_id, get_cover=key == 'cover') return mi.get(key, default) + def cover_last_modified(self, index, index_is_id=False): + book_id = index if index_is_id else self.id(index) + return self.new_api.cover_last_modified(book_id) or self.last_modified() + def authors_sort_strings(self, index, index_is_id=False): book_id = index if index_is_id else self.id(index) return list(self.new_api.author_sort_strings_for_books((book_id,))[book_id])