mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-24 02:14:52 +01:00
implement Database.get_version() and Database.needs_upgrade()
This commit is contained in:
parent
23b32a7dfd
commit
8345aab10c
2 changed files with 46 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
import ctypes
|
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
|
from cnotmuch.globals import nmlib, STATUS, NotmuchError, Enum
|
||||||
import logging
|
import logging
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
@ -23,6 +23,10 @@ class Database(object):
|
||||||
_get_path = nmlib.notmuch_database_get_path
|
_get_path = nmlib.notmuch_database_get_path
|
||||||
_get_path.restype = c_char_p
|
_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)"""
|
"""notmuch_database_open (const char *path, notmuch_database_mode_t mode)"""
|
||||||
_open = nmlib.notmuch_database_open
|
_open = nmlib.notmuch_database_open
|
||||||
_open.restype = c_void_p
|
_open.restype = c_void_p
|
||||||
|
@ -124,6 +128,35 @@ class Database(object):
|
||||||
Wraps notmuch_database_get_path"""
|
Wraps notmuch_database_get_path"""
|
||||||
return Database._get_path(self._db)
|
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):
|
def find_message(self, msgid):
|
||||||
"""Returns a :class:`Message` as identified by its message ID
|
"""Returns a :class:`Message` as identified by its message ID
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,18 @@ or::
|
||||||
|
|
||||||
.. automethod:: get_path
|
.. automethod:: get_path
|
||||||
|
|
||||||
|
.. automethod:: get_version
|
||||||
|
|
||||||
|
.. automethod:: needs_upgrade
|
||||||
|
|
||||||
|
.. automethod:: upgrade
|
||||||
|
|
||||||
|
.. automethod:: get_directory
|
||||||
|
|
||||||
|
.. automethod:: add_message
|
||||||
|
|
||||||
|
.. automethod:: remove_message
|
||||||
|
|
||||||
.. automethod:: find_message
|
.. automethod:: find_message
|
||||||
|
|
||||||
.. automethod:: get_all_tags
|
.. automethod:: get_all_tags
|
||||||
|
|
Loading…
Reference in a new issue