]> git.notmuchmail.org Git - notmuch/blobdiff - cnotmuch/database.py
docs: Various typo fixes in docstrings
[notmuch] / cnotmuch / database.py
index 6a74f5d58014eaafeaef4e79b4d0d936b0d77442..f611777cafbc869cbf3addc6f7e558f0f84c719a 100644 (file)
@@ -77,6 +77,11 @@ class Database(object):
         else:
             self.create(path)
 
+    def _verify_initialized_db(self):
+        """Raises a NotmuchError in case self._db is still None"""
+        if self._db is None:
+            raise NotmuchError(STATUS.NOT_INITIALIZED)            
+
     def create(self, path):
         """Creates a new notmuch database
 
@@ -129,6 +134,9 @@ class Database(object):
         """Returns the file path of an open database
 
         Wraps notmuch_database_get_path"""
+        # Raise a NotmuchError if not initialized
+        self._verify_initialized_db()
+
         return Database._get_path(self._db)
 
     def get_version(self):
@@ -138,8 +146,8 @@ class Database(object):
         :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
                     the database was not intitialized.
         """
-        if self._db is None:
-            raise NotmuchError(STATUS.NOT_INITIALIZED)
+        # Raise a NotmuchError if not initialized
+        self._verify_initialized_db()
 
         return Database._get_version (self._db)
 
@@ -155,8 +163,8 @@ class Database(object):
         :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
                     the database was not intitialized.
         """
-        if self._db is None:
-            raise NotmuchError(STATUS.NOT_INITIALIZED)
+        # Raise a NotmuchError if not initialized
+        self._verify_initialized_db()
 
         return notmuch_database_needs_upgrade(self.db) 
 
@@ -172,8 +180,9 @@ class Database(object):
         :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
                   the database was not intitialized.
         """
-        if self._db is None:
-            raise NotmuchError(STATUS.NOT_INITIALIZED)
+        # Raise a NotmuchError if not initialized
+        self._verify_initialized_db()
+
         msg_p = Database._find_message(self._db, msgid)
         if msg_p is None:
             return None
@@ -185,8 +194,8 @@ class Database(object):
         :returns: :class:`Tags`
         :execption: :exc:`NotmuchError` with STATUS.NULL_POINTER on error
         """
-        if self._db is None:
-            raise NotmuchError(STATUS.NOT_INITIALIZED)
+        # Raise a NotmuchError if not initialized
+        self._verify_initialized_db()
 
         tags_p = Database._get_all_tags (self._db)
         if tags_p == None:
@@ -218,14 +227,16 @@ class Database(object):
 
     @property
     def db_p(self):
-        """Property returning a pointer to the notmuch_database_t or `None`
+        """Property returning a pointer to `notmuch_database_t` or `None`
 
-        This should normally not be needed by a user."""
+        This should normally not be needed by a user (and is not yet
+        guaranteed to remain stable in future versions).
+        """
         return self._db
 
 #------------------------------------------------------------------------------
 class Query(object):
-    """ Represents a search query on an opened :class:`Database`.
+    """Represents a search query on an opened :class:`Database`.
 
     A query selects and filters a subset of messages from the notmuch
     database we derive from.
@@ -252,7 +263,7 @@ class Query(object):
 
 
     """notmuch_query_count_messages"""
-    _count_messages = _nmlib.notmuch_query_count_messages
+    _count_messages = nmlib.notmuch_query_count_messages
     _count_messages.restype = c_uint
 
     def __init__(self, db, querystr):
@@ -267,7 +278,7 @@ class Query(object):
         self.create(db, querystr)
 
     def create(self, db, querystr):
-        """Creates a new query derived from a Database.
+        """Creates a new query derived from a Database
 
         This function is utilized by __init__() and usually does not need to 
         be called directly.
@@ -336,9 +347,10 @@ class Query(object):
         """Estimate the number of messages matching the query
 
         This function performs a search and returns Xapian's best
-        guess as to the number of matching messages. It is somewhat
-        faster than performing :meth:`search_messages` and counting
-        the result with `len()`. Technically, it wraps the underlying
+        guess as to the number of matching messages. It is much faster
+        than performing :meth:`search_messages` and counting the
+        result with `len()` (although it always returned the same
+        result in my tests). Technically, it wraps the underlying
         *notmuch_query_count_messages* function.
 
         :returns: :class:`Messages`
@@ -619,10 +631,15 @@ class Message(object):
     """notmuch_message_get_filename (notmuch_message_t *message)"""
     _get_filename = nmlib.notmuch_message_get_filename
     _get_filename.restype = c_char_p 
+
     """notmuch_message_get_message_id (notmuch_message_t *message)"""
     _get_message_id = nmlib.notmuch_message_get_message_id
     _get_message_id.restype = c_char_p 
 
+    """notmuch_message_get_thread_id"""
+    _get_thread_id = nmlib.notmuch_message_get_thread_id
+    _get_thread_id.restype = c_char_p
+
     """notmuch_message_get_tags (notmuch_message_t *message)"""
     _get_tags = nmlib.notmuch_message_get_tags
     _get_tags.restype = c_void_p
@@ -652,7 +669,7 @@ class Message(object):
 
 
     def get_message_id(self):
-        """Return the message ID
+        """Returns the message ID
         
         :returns: String with a message ID
         :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message 
@@ -662,6 +679,24 @@ class Message(object):
             raise NotmuchError(STATUS.NOT_INITIALIZED)
         return Message._get_message_id(self._msg)
 
+    def get_thread_id(self):
+        """Returns the thread ID
+
+        The returned string belongs to 'message' will only be valid for as 
+        long as the message is valid.
+
+        This function will not return None since Notmuch ensures that every
+        message belongs to a single thread.
+
+        :returns: String with a thread ID
+        :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message 
+                    is not initialized.
+        """
+        if self._msg is None:
+            raise NotmuchError(STATUS.NOT_INITIALIZED)
+
+        return Message._get_thread_id (self._msg);
+
     def get_date(self):
         """Returns time_t of the message date