From: Michael J Gruber <git@grubix.eu>
To: notmuch@notmuchmail.org
Subject: [PATCH 3/3] python/notmuch2: provide binding for collect_tags()
Date: Wed, 6 Jan 2021 10:08:42 +0100 [thread overview]
Message-ID: <9c89dfcf04606c9f5c1d4514096499f3ae7323d0.1609347527.git.git@grubix.eu> (raw)
In-Reply-To: <cover.1609347527.git.git@grubix.eu>
collect_tags() is accessible in the legacy bindings as a method on the
messages object returned by searches. In the cffi bindings, neither
queries nor their internal values are exposed, so provide a binding
analogous to count_messages().
Signed-off-by: Michael J Gruber <git@grubix.eu>
---
bindings/python-cffi/notmuch2/_database.py | 17 +++++++++++++++++
bindings/python-cffi/notmuch2/_query.py | 12 ++++++++++++
2 files changed, 29 insertions(+)
diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py
index 7592956a..f3452e11 100644
--- a/bindings/python-cffi/notmuch2/_database.py
+++ b/bindings/python-cffi/notmuch2/_database.py
@@ -618,6 +618,23 @@ class Database(base.NotmuchObject):
exclude_tags=exclude_tags)
return query.count_messages()
+ def collect_tags(self, query, *,
+ omit_excluded=EXCLUDE.TRUE,
+ sort=SORT.UNSORTED, # Check this default
+ exclude_tags=None):
+ """Search the database for messages and collect tags.
+
+ :returns: The tags of all messages found.
+ :rtype: ImmutableTagset
+
+ :raises ObjectDestroyedError: if used after destroyed.
+ """
+ query = self._create_query(query,
+ omit_excluded=omit_excluded,
+ sort=sort,
+ exclude_tags=exclude_tags)
+ return query.collect_tags()
+
def threads(self, query, *,
omit_excluded=EXCLUDE.TRUE,
sort=SORT.UNSORTED, # Check this default
diff --git a/bindings/python-cffi/notmuch2/_query.py b/bindings/python-cffi/notmuch2/_query.py
index 1db6ec96..a1310944 100644
--- a/bindings/python-cffi/notmuch2/_query.py
+++ b/bindings/python-cffi/notmuch2/_query.py
@@ -2,6 +2,7 @@ from notmuch2 import _base as base
from notmuch2 import _capi as capi
from notmuch2 import _errors as errors
from notmuch2 import _message as message
+from notmuch2 import _tags as tags
from notmuch2 import _thread as thread
@@ -66,6 +67,17 @@ class Query(base.NotmuchObject):
raise errors.NotmuchError(ret)
return count_p[0]
+ def collect_tags(self):
+ """Return the tags of messages matching this query."""
+ msgs_pp = capi.ffi.new('notmuch_messages_t**')
+ ret = capi.lib.notmuch_query_search_messages(self._query_p, msgs_pp)
+ if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
+ raise errors.NotmuchError(ret)
+ self._msgs_p = msgs_pp[0]
+ tagset = tags.ImmutableTagSet(
+ self, '_msgs_p', capi.lib.notmuch_messages_collect_tags)
+ return tags.ImmutableTagSet._from_iterable(tagset)
+
def threads(self):
"""Return an iterator over all the threads found by the query."""
threads_pp = capi.ffi.new('notmuch_threads_t **')
--
2.30.0.rc0.297.gbcca948854
next prev parent reply other threads:[~2021-01-06 9:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-06 9:08 [PATCH 0/3] python/notmuch2: a few docstrings and collect_tags() Michael J Gruber
2021-01-06 9:08 ` [PATCH 1/3] python/notmuch2: correct docstring for Database.count_messages() Michael J Gruber
2021-01-06 9:08 ` [PATCH 2/3] python/notmuch2: docstrings for Database.threads(), Database.count_threads() Michael J Gruber
2021-01-06 9:08 ` Michael J Gruber [this message]
2021-01-11 20:33 ` [PATCH 3/3] python/notmuch2: provide binding for collect_tags() Floris Bruynooghe
2021-02-11 17:06 ` Michael J Gruber
2021-01-07 14:35 ` [PATCH 0/3] python/notmuch2: a few docstrings and collect_tags() David Bremner
[not found] ` <E1kxYme-0002nO-P1@sphinx.mythic-beasts.com>
2021-01-11 20:47 ` Floris Bruynooghe
2021-01-12 9:13 ` Michael J Gruber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9c89dfcf04606c9f5c1d4514096499f3ae7323d0.1609347527.git.git@grubix.eu \
--to=git@grubix.eu \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).