]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python-cffi/notmuch2/_database.py
python/notmuch2: add bindings for the database config strings
[notmuch] / bindings / python-cffi / notmuch2 / _database.py
index a1c624a7352232c21892949fabd24b9bc64c23e6..3c06402dcc35ed356850bc2d5c2cff59f5542094 100644 (file)
@@ -7,6 +7,7 @@ import pathlib
 import weakref
 
 import notmuch2._base as base
+import notmuch2._config as config
 import notmuch2._capi as capi
 import notmuch2._errors as errors
 import notmuch2._message as message
@@ -262,7 +263,7 @@ class Database(base.NotmuchObject):
 
         This is returned as a :class:`pathlib.Path` instance.
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         try:
             return self._cache_path
@@ -277,7 +278,7 @@ class Database(base.NotmuchObject):
 
         This is a positive integer.
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         try:
             return self._cache_version
@@ -296,7 +297,7 @@ class Database(base.NotmuchObject):
 
         A read-only database will never be upgradable.
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         ret = capi.lib.notmuch_database_needs_upgrade(self._db_p)
         return bool(ret)
@@ -320,7 +321,7 @@ class Database(base.NotmuchObject):
            not imply durability, it only ensures the changes are
            performed atomically.
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         ctx = AtomicContext(self, '_db_p')
         return ctx
@@ -330,7 +331,7 @@ class Database(base.NotmuchObject):
 
         Returned as a ``(revision, uuid)`` namedtuple.
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         raw_uuid = capi.ffi.new('char**')
         rev = capi.lib.notmuch_database_get_revision(self._db_p, raw_uuid)
@@ -342,7 +343,7 @@ class Database(base.NotmuchObject):
     def default_indexopts(self):
         """Returns default index options for the database.
 
-        :raises ObjectDestoryedError: if used after destroyed.
+        :raises ObjectDestroyedError: if used after destroyed.
 
         :returns: :class:`IndexOptions`.
         """
@@ -387,7 +388,7 @@ class Database(base.NotmuchObject):
            READ_ONLY mode.
         :raises UpgradeRequiredError: The database must be upgraded
            first.
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
             filename = bytes(filename)
@@ -426,7 +427,7 @@ class Database(base.NotmuchObject):
            READ_ONLY mode.
         :raises UpgradeRequiredError: The database must be upgraded
            first.
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
             filename = bytes(filename)
@@ -458,7 +459,7 @@ class Database(base.NotmuchObject):
         :raises OutOfMemoryError: When there is no memory to allocate
            the message instance.
         :raises XapianError: A Xapian exception ocurred.
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         msg_pp = capi.ffi.new('notmuch_message_t **')
         ret = capi.lib.notmuch_database_find_message(self._db_p,
@@ -489,7 +490,7 @@ class Database(base.NotmuchObject):
         :raises OutOfMemoryError: When there is no memory to allocate
            the message instance.
         :raises XapianError: A Xapian exception ocurred.
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         if not hasattr(os, 'PathLike') and isinstance(filename, pathlib.Path):
             filename = bytes(filename)
@@ -522,7 +523,7 @@ class Database(base.NotmuchObject):
 
         :rtype: ImmutableTagSet
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         try:
             ref = self._cached_tagset
@@ -536,6 +537,28 @@ class Database(base.NotmuchObject):
             self._cached_tagset = weakref.ref(tagset)
         return tagset
 
+    @property
+    def config(self):
+        """Return a mutable mapping with the settings stored in this database.
+
+        This returns an mutable dict-like object implementing the
+        collections.abc.MutableMapping Abstract Base Class.
+
+        :rtype: Config
+
+        :raises ObjectDestroyedError: if used after destroyed.
+        """
+        try:
+            ref = self._cached_config
+        except AttributeError:
+            config_mapping = None
+        else:
+            config_mapping = ref()
+        if config_mapping is None:
+            config_mapping = config.ConfigMapping(self, '_db_p')
+            self._cached_config = weakref.ref(config_mapping)
+        return config_mapping
+
     def _create_query(self, query, *,
                       omit_excluded=EXCLUDE.TRUE,
                       sort=SORT.UNSORTED,  # Check this default
@@ -570,7 +593,7 @@ class Database(base.NotmuchObject):
 
         :raises OutOfMemoryError: if no memory is available to
            allocate the query.
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         query = self._create_query(query,
                                    omit_excluded=omit_excluded,
@@ -587,7 +610,7 @@ class Database(base.NotmuchObject):
         :returns: An iterator over the messages found.
         :rtype: MessageIter
 
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         query = self._create_query(query,
                                    omit_excluded=omit_excluded,
@@ -635,7 +658,7 @@ class AtomicContext:
        section is not active.  When it is raised at exit time the
        atomic section is still active and you may need to try using
        :meth:`force_end`.
-    :raises ObjectDestroyedError: if used after destoryed.
+    :raises ObjectDestroyedError: if used after destroyed.
     """
 
     def __init__(self, db, ptr_name):
@@ -675,7 +698,7 @@ class AtomicContext:
            not ended.
         :raises UnbalancedAtomicError: If the database was currently
            not in an atomic section.
-        :raises ObjectDestroyedError: if used after destoryed.
+        :raises ObjectDestroyedError: if used after destroyed.
         """
         ret = capi.lib.notmuch_database_end_atomic(self._ptr())
         if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
@@ -770,7 +793,7 @@ class IndexOptions(base.NotmuchObject):
         You can change this policy by assigning a new
         :class:`DecryptionPolicy` to this property.
 
-        :raises ObjectDestoryedError: if used after destroyed.
+        :raises ObjectDestroyedError: if used after destroyed.
 
         :returns: A :class:`DecryptionPolicy` enum instance.
         """