aboutsummaryrefslogtreecommitdiff
path: root/bindings/python-cffi/notmuch2/_database.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2025-09-14 17:07:43 +0200
committerDavid Bremner <david@tethera.net>2025-09-14 13:24:59 -0300
commitabdff73a3333b295a599135ad2777e852189e188 (patch)
tree49b21ea4c526d5d1fb498ef9869b892ac296183d /bindings/python-cffi/notmuch2/_database.py
parentaa761727999b105711ba4ca789e0836a0a05cf9f (diff)
bindings/python-cffi: allow reopening a database
This will be useful for handling NOTMUCH_STATUS_OPERATION_INVALIDATED errors that will be exposed through the bindings in a following commit.
Diffstat (limited to 'bindings/python-cffi/notmuch2/_database.py')
-rw-r--r--bindings/python-cffi/notmuch2/_database.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py
index c13d9fcf..a47049ba 100644
--- a/bindings/python-cffi/notmuch2/_database.py
+++ b/bindings/python-cffi/notmuch2/_database.py
@@ -285,6 +285,30 @@ class Database(base.NotmuchObject):
raise errors.NotmuchError(ret)
self.closed = True
+ def reopen(self, mode=None):
+ """Reopen an opened notmuch database.
+
+ :param mode: Mode to reopen the database with. When None, the previously
+ active mode is preserved.
+ :type mode: :attr:`MODE`, str, or None.
+
+ This is useful e.g. for:
+ - switching the mode between read-only and read-write
+ - recovering from OperationInvalidatedError
+ """
+ if isinstance(mode, str):
+ try:
+ mode = self.STR_MODE_MAP[mode]
+ except KeyError:
+ raise ValueError('Invalid mode: %s' % mode)
+ else:
+ mode = mode or self.mode
+ self.mode = mode
+
+ ret = capi.lib.notmuch_database_reopen(self._db_p, mode.value)
+ if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
+ raise errors.NotmuchError(ret)
+
def __enter__(self):
return self