aboutsummaryrefslogtreecommitdiffhomepage
path: root/bindings
diff options
context:
space:
mode:
authorGravatar Justus Winter <4winter@informatik.uni-hamburg.de>2012-02-15 22:25:13 +0100
committerGravatar Justus Winter <4winter@informatik.uni-hamburg.de>2012-02-15 22:25:13 +0100
commitb2734519db78fdec76eeafc5fe8f5631a6436cf6 (patch)
treefec1ca91ee828e4f62be26986e82035bebc7cda8 /bindings
parent5f39979a4aa2aea7d587201702fa3443248334bd (diff)
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>
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/notmuch/database.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 36b65ecb..d0e38dda 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -142,6 +142,9 @@ class Database(object):
else:
self.create(path)
+ def __del__(self):
+ self.close()
+
def _assert_db_is_initialized(self):
"""Raises :exc:`NotInitializedError` 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")
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):
"""Returns the file path of an open database"""
self._assert_db_is_initialized()
@@ -531,15 +544,6 @@ class Database(object):
def __repr__(self):
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):
""" Reads a user's notmuch config and returns his db location