]> git.notmuchmail.org Git - notmuch/blob - cnotmuch/globals.py
ff765167a7974ec0bd0ade1c102e128fbe920533
[notmuch] / cnotmuch / globals.py
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')
5
6 class STATUS(object):
7   SUCCESS = 0
8   OUT_OF_MEMORY = 1
9   READ_ONLY_DATABASE = 2
10   XAPIAN_EXCEPTION = 3
11   FILE_ERROR = 4
12   FILE_NOT_EMAIL = 5
13   DUPLICATE_MESSAGE_ID = 6
14   NULL_POINTER = 7
15   TAG_TOO_LONG = 8
16   UNBALANCED_FREEZE_THAW = 9
17   LAST_STATUS = 10
18
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]
23
24   def __init__(self, status):
25       self._status = status
26
27   def __str__(self):
28       """Get a string representation of a notmuch_status_t value."""   
29       return str(STATUS.status2str(self._status))
30
31 class NotmuchError(Exception):
32     def __init__(self, status=None, message=None):
33         """Is initiated with a (notmuch.STATUS[,message=None])"""
34         super(NotmuchError, self).__init__(message, status)
35
36     def __str__(self):
37         if self.args[0] is not None: return self.args[0]
38         else: return str(STATUS(self.args[1]))