1 from ctypes import CDLL, c_char_p, c_int
2 #package-global instance of the notmuch library
3 #TODO: lazy load this on first access?
4 nmlib = CDLL('/usr/local/lib/libnotmuch.so')
13 DUPLICATE_MESSAGE_ID = 6
16 UNBALANCED_FREEZE_THAW = 9
19 """Get a string representation of a notmuch_status_t value."""
20 status2str = nmlib.notmuch_status_to_string
21 status2str.restype = c_char_p
22 status2str.argtypes = [c_int]
24 def __init__(self, status):
28 """Get a string representation of a notmuch_status_t value."""
29 # define strings for custom error messages
30 if self._status == STATUS.NOT_INITIALIZED:
31 return "Operation on uninitialized DB/MSG/THREAD impossible."
32 return str(STATUS.status2str(self._status))
34 class NotmuchError(Exception):
35 def __init__(self, status=None, message=None):
36 """Is initiated with a (notmuch.STATUS[,message=None])"""
37 super(NotmuchError, self).__init__(message, status)
40 if self.args[0] is not None: return self.args[0]
41 else: return str(STATUS(self.args[1]))