X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=cnotmuch%2Fglobals.py;h=611c29ed8fcee4f93cc27503d81536801c935c37;hb=bb5870b9af7d023d7d61233dc19d73772d84fdc5;hp=ff765167a7974ec0bd0ade1c102e128fbe920533;hpb=b4fdf0ae30e0847a759c01524898d0b9d803c43b;p=notmuch diff --git a/cnotmuch/globals.py b/cnotmuch/globals.py index ff765167..611c29ed 100644 --- a/cnotmuch/globals.py +++ b/cnotmuch/globals.py @@ -1,7 +1,14 @@ from ctypes import CDLL, c_char_p, c_int +from ctypes.util import find_library + +#----------------------------------------------------------------------------- #package-global instance of the notmuch library #TODO: lazy load this on first access? -nmlib = CDLL('/usr/local/lib/libnotmuch.so') +so = find_library('notmuch') +if so is None: + raise ImportError("Could not find shared 'notmuch' library.") +nmlib = CDLL(so) +#----------------------------------------------------------------------------- class STATUS(object): SUCCESS = 0 @@ -14,7 +21,7 @@ class STATUS(object): NULL_POINTER = 7 TAG_TOO_LONG = 8 UNBALANCED_FREEZE_THAW = 9 - LAST_STATUS = 10 + NOT_INITIALIZED = 10 """Get a string representation of a notmuch_status_t value.""" status2str = nmlib.notmuch_status_to_string @@ -26,6 +33,9 @@ class STATUS(object): def __str__(self): """Get a string representation of a notmuch_status_t value.""" + # define strings for custom error messages + if self._status == STATUS.NOT_INITIALIZED: + return "Operation on uninitialized DB/MSG/THREAD impossible." return str(STATUS.status2str(self._status)) class NotmuchError(Exception):