summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-02-05 20:05:45 +0100
committerAnton Khirnov <anton@khirnov.net>2022-02-05 20:05:45 +0100
commite7e068ce31f1c78951df5d382580a78415563280 (patch)
treeda1eb5575a800ede230d4c835a795be09b549f19
parent222ebaed846ba6739e17a09c2b16f10c853790bf (diff)
db/manager: support flexible database location
In newer notmuch versions it no longer needs to be stored along with the emails themselves.
-rw-r--r--alot/__main__.py6
-rw-r--r--alot/db/manager.py42
2 files changed, 17 insertions, 31 deletions
diff --git a/alot/__main__.py b/alot/__main__.py
index c74e5d6f..d9c69149 100644
--- a/alot/__main__.py
+++ b/alot/__main__.py
@@ -123,9 +123,9 @@ def main():
loop = asyncio.get_event_loop()
# get ourselves a database manager
- indexpath = settings.get_notmuch_setting('database', 'path')
- indexpath = options.mailindex_path or indexpath
- dbman = DBManager(loop, path=indexpath, ro=options.read_only)
+ db_path = options.mailindex_path or None
+ dbman = DBManager(loop = loop, ro = options.read_only,
+ db_path = db_path)
# determine what to do
if command is None:
diff --git a/alot/db/manager.py b/alot/db/manager.py
index efd70e70..c3d7507b 100644
--- a/alot/db/manager.py
+++ b/alot/db/manager.py
@@ -7,25 +7,15 @@ from concurrent.futures import ThreadPoolExecutor
from contextlib import closing
from functools import partial, partialmethod
import logging
-import os
from notmuch2 import Database, NotmuchError
-from .errors import (DatabaseError, DatabaseROError, NonexistantObjectError,
+from .errors import (DatabaseROError, NonexistantObjectError,
QueryError)
from .sort import ORDER
from .thread import Thread
from ..settings.const import settings
-def _is_subdir_of(subpath, superpath):
- # make both absolute
- superpath = os.path.realpath(superpath)
- subpath = os.path.realpath(subpath)
-
- # return true, if the common prefix of both is equal to directory
- # e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b
- return os.path.commonprefix([subpath, superpath]) == superpath
-
# DB write operations
class _DBWriteList:
"""
@@ -44,7 +34,9 @@ class _DBWriteList:
logging.debug('Performing DB write: %s', self)
try:
- with Database(self._dbman.path, Database.MODE.READ_WRITE) as db:
+ with Database(path = self._dbman._db_path,
+ config = self._dbman._config_path,
+ mode = Database.MODE.READ_WRITE) as db:
logging.debug('got writeable DB')
with db.atomic():
@@ -118,7 +110,9 @@ class DBManager:
lets you look up threads and messages directly to the persistent wrapper
classes.
"""
- """constants representing sort orders"""
+
+ _db_path = None
+ _config_path = None
_loop = None
@@ -130,15 +124,12 @@ class DBManager:
_write_task = None
_write_queue = None
- def __init__(self, loop, path=None, ro=False):
- """
- :param path: absolute path to the notmuch index
- :type path: str
- :param ro: open the index in read-only mode
- :type ro: bool
- """
+ def __init__(self, loop, ro = False,
+ db_path = None, config_path = Database.CONFIG.SEARCH):
self.ro = ro
- self.path = path
+
+ self._db_path = db_path
+ self._config_path = config_path
self._loop = loop
@@ -149,7 +140,8 @@ class DBManager:
self._property_tags = frozenset(settings.get('property_tags'))
def _db_ro(self):
- return closing(Database(path = self.path, mode = Database.MODE.READ_ONLY))
+ return closing(Database(path = self._db_path, config = self._config_path,
+ mode = Database.MODE.READ_ONLY))
def _count(self, what, querystring):
try:
@@ -301,12 +293,6 @@ class DBManager:
:param tags: tagstrings to add
:type tags: list of str
"""
- if not _is_subdir_of(path, self.path):
- msg = 'message path %s ' % path
- msg += ' is not below notmuchs '
- msg += 'root path (%s)' % self.path
- raise DatabaseError(msg)
-
ret = self.db_write_create()
ret.queue_msg_add(path, tags)
return ret.apply()