summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-30 19:59:02 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-30 19:59:02 +0100
commitc341b45a8582ba114301e5ab0f30a28a5b1c6691 (patch)
treedec821f85d0b74ce20699dd19ba9d83f7c9cc96b
parent5c7200b4130108848085ed294d2c956ff0b047d6 (diff)
db/manager: handle notmuch exceptions in count_*
-rw-r--r--alot/db/manager.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py
index 4d9b5778..c4ec02d1 100644
--- a/alot/db/manager.py
+++ b/alot/db/manager.py
@@ -5,6 +5,7 @@
import abc
import asyncio
from contextlib import closing
+from functools import partialmethod
import logging
import os
@@ -154,15 +155,19 @@ class DBManager:
def _db_ro(self):
return closing(Database(path = self.path, mode = Database.MODE.READ_ONLY))
- def count_messages(self, querystring):
- """returns number of messages that match `querystring`"""
- with self._db_ro() as db:
- return db.count_messages(querystring, exclude_tags = self._exclude_tags)
+ def _count(self, what, querystring):
+ try:
+ with self._db_ro() as db:
+ func = getattr(db, 'count_' +what)
+ return func(querystring, exclude_tags = self._exclude_tags)
+ except NotmuchError:
+ return -1
- def count_threads(self, querystring):
- """returns number of threads that match `querystring`"""
- with self._db_ro() as db:
- return db.count_threads(querystring, exclude_tags = self._exclude_tags)
+ count_messages = partialmethod(_count, 'messages')
+ """returns number of messages that match `querystring`"""
+
+ count_threads = partialmethod(_count, 'threads')
+ """returns number of threads that match `querystring`"""
def _get_notmuch_thread(self, db, tid):
"""returns :class:`notmuch.database.Thread` with given id"""