mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-01-24 04:04:24 +01:00
python: provide a Database.close function
Rename Database.__del__ to Database.close, move it just below the open function and call close() in a newly created destructor just below the constructor. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
This commit is contained in:
parent
5f39979a4a
commit
b2734519db
1 changed files with 13 additions and 9 deletions
|
@ -142,6 +142,9 @@ class Database(object):
|
||||||
else:
|
else:
|
||||||
self.create(path)
|
self.create(path)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.close()
|
||||||
|
|
||||||
def _assert_db_is_initialized(self):
|
def _assert_db_is_initialized(self):
|
||||||
"""Raises :exc:`NotInitializedError` if self._db is `None`"""
|
"""Raises :exc:`NotInitializedError` if self._db is `None`"""
|
||||||
if self._db is None:
|
if self._db is None:
|
||||||
|
@ -193,6 +196,16 @@ class Database(object):
|
||||||
raise NotmuchError(message="Could not open the specified database")
|
raise NotmuchError(message="Could not open the specified database")
|
||||||
self._db = res
|
self._db = res
|
||||||
|
|
||||||
|
_close = nmlib.notmuch_database_close
|
||||||
|
_close.argtypes = [NotmuchDatabaseP]
|
||||||
|
_close.restype = None
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
"""Close and free the notmuch database if needed"""
|
||||||
|
if self._db is not None:
|
||||||
|
self._close(self._db)
|
||||||
|
self._db = None
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
"""Returns the file path of an open database"""
|
"""Returns the file path of an open database"""
|
||||||
self._assert_db_is_initialized()
|
self._assert_db_is_initialized()
|
||||||
|
@ -531,15 +544,6 @@ class Database(object):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "'Notmuch DB " + self.get_path() + "'"
|
return "'Notmuch DB " + self.get_path() + "'"
|
||||||
|
|
||||||
_close = nmlib.notmuch_database_close
|
|
||||||
_close.argtypes = [NotmuchDatabaseP]
|
|
||||||
_close.restype = None
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
"""Close and free the notmuch database if needed"""
|
|
||||||
if self._db is not None:
|
|
||||||
self._close(self._db)
|
|
||||||
|
|
||||||
def _get_user_default_db(self):
|
def _get_user_default_db(self):
|
||||||
""" Reads a user's notmuch config and returns his db location
|
""" Reads a user's notmuch config and returns his db location
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue