From e16f04e7b7fbd3b99826f1495d7002c2826bf79c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 27 Feb 2011 16:18:56 -0700 Subject: [PATCH] When keeping x periodical issues be a little more careful about what we delete --- src/calibre/gui2/actions/fetch_news.py | 3 ++- src/calibre/library/database2.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/actions/fetch_news.py b/src/calibre/gui2/actions/fetch_news.py index fe51012e31..f7756efbab 100644 --- a/src/calibre/gui2/actions/fetch_news.py +++ b/src/calibre/gui2/actions/fetch_news.py @@ -67,7 +67,8 @@ class FetchNewsAction(InterfaceAction): keep_issues = 0 if keep_issues > 0: ids_with_tag = list(sorted(self.gui.library_view.model(). - db.tags_older_than(arg['title'], None), reverse=True)) + db.tags_older_than(arg['title'], + None, must_have_tag=_('News')), reverse=True)) ids_to_delete = ids_with_tag[keep_issues:] if ids_to_delete: self.gui.library_view.model().delete_books_by_id(ids_to_delete) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 4d6681b91d..8e90fe77bd 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1503,25 +1503,30 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): ############# End get_categories - def tags_older_than(self, tag, delta): + def tags_older_than(self, tag, delta, must_have_tag=None): ''' Return the ids of all books having the tag ``tag`` that are older than than the specified time. tag comparison is case insensitive. :param delta: A timedelta object or None. If None, then all ids with the tag are returned. + :param must_have_tag: If not None the list of matches will be + restricted to books that have this tag ''' tag = tag.lower().strip() + mht = must_have_tag.lower().strip() if must_have_tag else None now = nowf() tindex = self.FIELD_MAP['timestamp'] gindex = self.FIELD_MAP['tags'] + iindex = self.FIELD_MAP['id'] for r in self.data._data: if r is not None: if delta is None or (now - r[tindex]) > delta: tags = r[gindex] - if tags and tag in [x.strip() for x in - tags.lower().split(',')]: - yield r[self.FIELD_MAP['id']] + if tags: + tags = [x.strip() for x in tags.lower().split(',')] + if tag in tags and (mht is None or mht in tags): + yield r[iindex] def get_next_series_num_for(self, series): series_id = self.conn.get('SELECT id from series WHERE name=?',