X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=cnotmuch%2Fdatabase.py;h=ad84f5eb2048628b20a194d8539e0eae6bbe1ef8;hp=79f57ea2275f2a12ea7e57f50491068899cbb3a4;hb=8345aab10c56dc4fe3ae7619042111524a062549;hpb=350509028b1213402854e18b213a5a47b1dddc1c diff --git a/cnotmuch/database.py b/cnotmuch/database.py index 79f57ea2..ad84f5eb 100644 --- a/cnotmuch/database.py +++ b/cnotmuch/database.py @@ -1,5 +1,5 @@ import ctypes -from ctypes import c_int, c_char_p, c_void_p, c_uint64 +from ctypes import c_int, c_char_p, c_void_p, c_uint, c_uint64, c_bool from cnotmuch.globals import nmlib, STATUS, NotmuchError, Enum import logging from datetime import date @@ -23,6 +23,10 @@ class Database(object): _get_path = nmlib.notmuch_database_get_path _get_path.restype = c_char_p + """notmuch_database_get_version""" + _get_version = nmlib.notmuch_database_get_version + _get_version.restype = c_uint + """notmuch_database_open (const char *path, notmuch_database_mode_t mode)""" _open = nmlib.notmuch_database_open _open.restype = c_void_p @@ -124,6 +128,35 @@ class Database(object): Wraps notmuch_database_get_path""" return Database._get_path(self._db) + def get_version(self): + """Returns the database format version + + :returns: The database version as positive integer + :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if + the database was not intitialized. + """ + if self._db is None: + raise NotmuchError(STATUS.NOT_INITIALIZED) + + return Database._get_version (self._db) + + def needs_upgrade(self): + """Does this database need to be upgraded before writing to it? + + If this function returns TRUE then no functions that modify the + database (:meth:`Database.add_message`, :meth:`Database.add_tag`, + :meth:`Directory.set_mtime`, etc.) will work unless :meth:`upgrade` + is called successfully first. + + :returns: `True` or `False` + :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if + the database was not intitialized. + """ + if self._db is None: + raise NotmuchError(STATUS.NOT_INITIALIZED) + + return notmuch_database_needs_upgrade(self.db) + def find_message(self, msgid): """Returns a :class:`Message` as identified by its message ID @@ -714,8 +747,12 @@ class Message(object): def remove_tag(self, tag): """Removes a tag from the given message + If the message has no such tag, this is a non-operation and + will report success anyway. + :param tag: String with a 'tag' to be removed. - :returns: STATUS.SUCCESS if the tag was successfully removed. + :returns: STATUS.SUCCESS if the tag was successfully removed or if + the message had no such tag. Raises an exception otherwise. :exception: :exc:`NotmuchError`. They have the following meaning: