NotmuchError,
NullPointerError,
NotInitializedError,
+ ReadOnlyDatabaseError,
Enum,
_str,
NotmuchDatabaseP,
_create.argtypes = [c_char_p]
_create.restype = NotmuchDatabaseP
- def __init__(self, path=None, create=False, mode=0):
+ def __init__(self, path = None, create = False,
+ mode = MODE.READ_ONLY):
"""If *path* is `None`, we will try to read a users notmuch
configuration and use his configured database. The location of the
configuration file can be specified through the environment variable
failure.
"""
self._db = None
+ self.mode = mode
if path is None:
# no path specified. use a user's default database
if Database._std_db_path is None:
:param path: A directory in which we should create the database.
:type path: str
- :returns: Nothing
:raises: :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
:param status: Open the database in read-only or read-write mode
:type status: :attr:`MODE`
- :returns: Nothing
:raises: Raises :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
"""Returns a :class:`Directory` of path,
(creating it if it does not exist(?))
- .. warning::
-
- This call needs a writeable database in
- :attr:`Database.MODE`.READ_WRITE mode. The underlying library will
- exit the program if this method is used on a read-only database!
-
:param path: An unicode string containing the path relative to the path
of database (see :meth:`get_path`), or else should be an absolute
path with initial components that match the path of 'database'.
:returns: :class:`Directory` or raises an exception.
- :raises:
- :exc:`NotmuchError` with :attr:`STATUS`.FILE_ERROR
- If path is not relative database or absolute with initial
- components same as database.
+ :raises: :exc:`FileError` if path is not relative database or absolute
+ with initial components same as database.
+ :raises: :exc:`ReadOnlyDatabaseError` if the database has not been
+ opened in read-write mode
"""
self._assert_db_is_initialized()
+
+ # work around libnotmuch calling exit(3), see
+ # id:20120221002921.8534.57091@thinkbox.jade-hamburg.de
+ # TODO: remove once this issue is resolved
+ if self.mode != Database.MODE.READ_WRITE:
+ raise ReadOnlyDatabaseError('The database has to be opened in '
+ 'read-write mode for get_directory')
+
# sanity checking if path is valid, and make path absolute
- if path[0] == os.sep:
+ if path and path[0] == os.sep:
# we got an absolute path
if not path.startswith(self.get_path()):
# but its initial components are not equal to the db path
dir_p = Database._get_directory(self._db, _str(path))
# return the Directory, init it with the absolute path
- return Directory(_str(abs_dirpath), dir_p, self)
+ return Directory(abs_dirpath, dir_p, self)
_add_message = nmlib.notmuch_database_add_message
_add_message.argtypes = [NotmuchDatabaseP, c_char_p,
def find_message_by_filename(self, filename):
"""Find a message with the given filename
- .. warning::
-
- This call needs a writeable database in
- :attr:`Database.MODE`.READ_WRITE mode. The underlying library will
- exit the program if this method is used on a read-only database!
-
:returns: If the database contains a message with the given
filename, then a class:`Message:` is returned. This
function returns None if no message is found with the given
filename.
- :raises:
- :exc:`OutOfMemoryError`
- If an Out-of-memory occured while constructing the message.
- :exc:`XapianError`
- In case of a Xapian Exception. These exceptions
- include "Database modified" situations, e.g. when the
- notmuch database has been modified by another program
- in the meantime. In this case, you should close and
- reopen the database and retry.
- :exc:`NotInitializedError` if
- the database was not intitialized.
+ :raises: :exc:`OutOfMemoryError` if an Out-of-memory occured while
+ constructing the message.
+ :raises: :exc:`XapianError` in case of a Xapian Exception.
+ These exceptions include "Database modified"
+ situations, e.g. when the notmuch database has been
+ modified by another program in the meantime. In this
+ case, you should close and reopen the database and
+ retry.
+ :raises: :exc:`NotInitializedError` if the database was not
+ intitialized.
+ :raises: :exc:`ReadOnlyDatabaseError` if the database has not been
+ opened in read-write mode
*Added in notmuch 0.9*"""
self._assert_db_is_initialized()
+
+ # work around libnotmuch calling exit(3), see
+ # id:20120221002921.8534.57091@thinkbox.jade-hamburg.de
+ # TODO: remove once this issue is resolved
+ if self.mode != Database.MODE.READ_WRITE:
+ raise ReadOnlyDatabaseError('The database has to be opened in '
+ 'read-write mode for get_directory')
+
msg_p = NotmuchMessageP()
status = Database._find_message_by_filename(self._db, _str(filename),
byref(msg_p))
def __init__(self, path, dir_p, parent):
"""
- :param path: The absolute path of the directory object as unicode.
+ :param path: The absolute path of the directory object.
:param dir_p: The pointer to an internal notmuch_directory_t object.
:param parent: The object this Directory is derived from
(usually a :class:`Database`). We do not directly use
this Directory object lives. This keeps the
parent object alive.
"""
- assert isinstance(path, unicode), "Path needs to be an UNICODE object"
self._path = path
self._dir_p = dir_p
self._parent = parent
Retrieves a previously stored mtime for this directory.
:param mtime: A (time_t) timestamp
- :returns: Nothing on success, raising an exception on failure.
:raises: :exc:`NotmuchError`:
:attr:`STATUS`.NOT_INITIALIZED