1 from ctypes import CDLL, c_char_p, c_int
2 from ctypes.util import find_library
4 #-----------------------------------------------------------------------------
5 #package-global instance of the notmuch library
6 #TODO: lazy load this on first access?
7 so = find_library('notmuch')
9 raise ImportError("Could not find shared 'notmuch' library.")
11 #-----------------------------------------------------------------------------
16 READ_ONLY_DATABASE = 2
20 DUPLICATE_MESSAGE_ID = 6
23 UNBALANCED_FREEZE_THAW = 9
26 """Get a string representation of a notmuch_status_t value."""
27 status2str = nmlib.notmuch_status_to_string
28 status2str.restype = c_char_p
29 status2str.argtypes = [c_int]
31 def __init__(self, status):
35 """Get a string representation of a notmuch_status_t value."""
36 # define strings for custom error messages
37 if self._status == STATUS.NOT_INITIALIZED:
38 return "Operation on uninitialized DB/MSG/THREAD impossible."
39 return str(STATUS.status2str(self._status))
41 class NotmuchError(Exception):
42 def __init__(self, status=None, message=None):
43 """Is initiated with a (notmuch.STATUS[,message=None])"""
44 super(NotmuchError, self).__init__(message, status)
47 if self.args[0] is not None: return self.args[0]
48 else: return str(STATUS(self.args[1]))