X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bindings%2Fpython-cffi%2Fnotmuch2%2F_database.py;h=7db5a7f85b224505523fbd1dbdbdcb797bd341d5;hb=776a54a0e437651abd69a03b9f7d591ea1f992cb;hp=fc55fea8f50bd0260c377dde7fd69919875fe02c;hpb=131757907907380213b32934d9e73cec942ace43;p=notmuch diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py index fc55fea8..7db5a7f8 100644 --- a/bindings/python-cffi/notmuch2/_database.py +++ b/bindings/python-cffi/notmuch2/_database.py @@ -400,7 +400,7 @@ class Database(base.NotmuchObject): capi.lib.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID] if ret not in ok: raise errors.NotmuchError(ret) - msg = message.StandaloneMessage(self, msg_pp[0], db=self) + msg = message.Message(self, msg_pp[0], db=self) if sync_flags: msg.tags.from_maildir_flags() return self.AddedMessage( @@ -469,7 +469,7 @@ class Database(base.NotmuchObject): msg_p = msg_pp[0] if msg_p == capi.ffi.NULL: raise LookupError - msg = message.StandaloneMessage(self, msg_p, db=self) + msg = message.Message(self, msg_p, db=self) return msg def get(self, filename): @@ -502,7 +502,7 @@ class Database(base.NotmuchObject): msg_p = msg_pp[0] if msg_p == capi.ffi.NULL: raise LookupError - msg = message.StandaloneMessage(self, msg_p, db=self) + msg = message.Message(self, msg_p, db=self) return msg @property @@ -664,6 +664,7 @@ class AtomicContext: def __init__(self, db, ptr_name): self._db = db self._ptr = lambda: getattr(db, ptr_name) + self._exit_fn = lambda: None def __del__(self): self._destroy() @@ -679,13 +680,17 @@ class AtomicContext: ret = capi.lib.notmuch_database_begin_atomic(self._ptr()) if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) + self._exit_fn = self._end_atomic return self - def __exit__(self, exc_type, exc_value, traceback): + def _end_atomic(self): ret = capi.lib.notmuch_database_end_atomic(self._ptr()) if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) + def __exit__(self, exc_type, exc_value, traceback): + self._exit_fn() + def force_end(self): """Force ending the atomic section. @@ -704,6 +709,15 @@ class AtomicContext: if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) + def abort(self): + """Abort the transaction. + + Aborting a transaction will not commit any of the changes, but + will also implicitly close the database. + """ + self._exit_fn = lambda: None + self._db.close() + @functools.total_ordering class DbRevision: