From 5633569aaf1be348759be92c0da833d340509edf Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Wed, 7 Aug 2024 12:04:35 +0100 Subject: [PATCH 1/2] notmuch2 copatibility This change causes alot to pass on the "notmuch-config" option (path to notmuch's configuration file) to any call to `Database(..)` in the underlying database. --- alot/__main__.py | 3 ++- alot/db/manager.py | 33 ++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/alot/__main__.py b/alot/__main__.py index 88ef3c0f2..21f85be57 100644 --- a/alot/__main__.py +++ b/alot/__main__.py @@ -124,7 +124,8 @@ def main(): # get ourselves a database manager indexpath = settings.get_notmuch_setting('database', 'path') indexpath = options.mailindex_path or indexpath - dbman = DBManager(path=indexpath, ro=options.read_only) + dbman = DBManager(path=indexpath, ro=options.read_only, + config=options.notmuch_config) # determine what to do if command is None: diff --git a/alot/db/manager.py b/alot/db/manager.py index 4980a996c..71d2e1370 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -33,15 +33,18 @@ class DBManager: } """constants representing sort orders""" - def __init__(self, path=None, ro=False): + def __init__(self, path=None, ro=False, config=None): """ :param path: absolute path to the notmuch index :type path: str :param ro: open the index in read-only mode :type ro: bool + :param path: absolute path to the notmuch config file + :type path: str """ self.ro = ro self.path = path + self.config = config self.writequeue = deque([]) self.processes = [] @@ -87,7 +90,8 @@ def flush(self): # acquire a writeable db handler try: mode = Database.MODE.READ_WRITE - db = Database(path=self.path, mode=mode) + db = Database(path=self.path, mode=mode, + config=self.config) except NotmuchError: raise DatabaseLockedError() logging.debug('got write lock') @@ -249,13 +253,15 @@ def toggle_tags(self, querystring, tags, afterwards=None): def count_messages(self, querystring): """returns number of messages that match `querystring`""" - db = Database(path=self.path, mode=Database.MODE.READ_ONLY) + db = Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) return db.count_messages(querystring, exclude_tags=self.exclude_tags) def collect_tags(self, querystring): """returns tags of messages that match `querystring`""" - db = Database(path=self.path, mode=Database.MODE.READ_ONLY) + db = Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) tagset = notmuch2._tags.ImmutableTagSet( db.messages(querystring, exclude_tags=self.exclude_tags), @@ -265,14 +271,16 @@ def collect_tags(self, querystring): def count_threads(self, querystring): """returns number of threads that match `querystring`""" - db = Database(path=self.path, mode=Database.MODE.READ_ONLY) + db = Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) return db.count_threads(querystring, exclude_tags=self.exclude_tags) @contextlib.contextmanager def _with_notmuch_thread(self, tid): """returns :class:`notmuch2.Thread` with given id""" - with Database(path=self.path, mode=Database.MODE.READ_ONLY) as db: + with Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) as db: try: yield next(db.threads('thread:' + tid)) except NotmuchError: @@ -287,8 +295,8 @@ def get_thread(self, tid): @contextlib.contextmanager def _with_notmuch_message(self, mid): """returns :class:`notmuch2.Message` with given id""" - mode = Database.MODE.READ_ONLY - with Database(path=self.path, mode=mode) as db: + with Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) as db: try: yield db.find_message(mid) except: @@ -305,7 +313,8 @@ def get_all_tags(self): returns all tagsstrings used in the database :rtype: list of str """ - db = Database(path=self.path, mode=Database.MODE.READ_ONLY) + db = Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) return [t for t in db.tags] def get_named_queries(self): @@ -313,7 +322,8 @@ def get_named_queries(self): returns the named queries stored in the database. :rtype: dict (str -> str) mapping alias to full query string """ - db = Database(path=self.path, mode=Database.MODE.READ_ONLY) + db = Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) return {k[6:]: db.config[k] for k in db.config if k.startswith('query.')} @@ -332,7 +342,8 @@ def get_threads(self, querystring, sort='newest_first'): :class:`multiprocessing.Process`) """ assert sort in self._sort_orders - db = Database(path=self.path, mode=Database.MODE.READ_ONLY) + db = Database(path=self.path, mode=Database.MODE.READ_ONLY, + config=self.config) thread_ids = [t.threadid for t in db.threads(querystring, sort=self._sort_orders[sort], exclude_tags=self.exclude_tags)] From 82f4ae5b4cc6ea5a4797b1ca29bc550b766ba6ed Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Sat, 10 Aug 2024 09:45:43 +0200 Subject: [PATCH 2/2] Fix typos --- alot/db/manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alot/db/manager.py b/alot/db/manager.py index 71d2e1370..39c34e2e3 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -39,7 +39,7 @@ def __init__(self, path=None, ro=False, config=None): :type path: str :param ro: open the index in read-only mode :type ro: bool - :param path: absolute path to the notmuch config file + :param config: absolute path to the notmuch config file :type path: str """ self.ro = ro @@ -83,7 +83,7 @@ def flush(self): # watch out for notmuch errors to re-insert current_item # to the queue on errors try: - # the first two coordinants are cnmdname and post-callback + # the first two coordinates are cnmdname and post-callback cmd, afterwards = current_item[:2] logging.debug('cmd created')