summaryrefslogtreecommitdiff
path: root/alot/db
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-31 09:51:36 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-31 09:51:36 +0100
commitc83da858d191c663894bef6d192d9bb489b082f5 (patch)
treeae86ac2856d560c0a7c1c44acdf0c7249e8bb975 /alot/db
parentcf6d0be6502b790f91c7f4e0f1738ef8381fab70 (diff)
db: use symbolic constants for sort orders
Diffstat (limited to 'alot/db')
-rw-r--r--alot/db/manager.py19
-rw-r--r--alot/db/sort.py14
2 files changed, 19 insertions, 14 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py
index c4ec02d1..e57af181 100644
--- a/alot/db/manager.py
+++ b/alot/db/manager.py
@@ -14,6 +14,7 @@ from notmuch2 import Database, NotmuchError
from .errors import DatabaseError
from .errors import DatabaseROError
from .errors import NonexistantObjectError
+from .sort import ORDER
from .thread import Thread
from ..settings.const import settings
@@ -116,12 +117,6 @@ class DBManager:
lets you look up threads and messages directly to the persistent wrapper
classes.
"""
- _sort_orders = {
- 'oldest_first': Database.SORT.OLDEST_FIRST,
- 'newest_first': Database.SORT.NEWEST_FIRST,
- 'unsorted': Database.SORT.UNSORTED,
- 'message_id': Database.SORT.MESSAGE_ID,
- }
"""constants representing sort orders"""
_loop = None
@@ -202,25 +197,21 @@ class DBManager:
queries = filter(lambda k: k.startswith(q_prefix), db.config)
return { q[len(q_prefix):] : db.config[q] for q in queries }
- def get_threads(self, querystring, sort='newest_first', exclude_tags = frozenset()):
+ def get_threads(self, querystring, sort = ORDER.NEWEST_FIRST,
+ exclude_tags = frozenset()):
"""
asynchronously look up thread ids matching `querystring`.
:param querystring: The query string to use for the lookup
:type querystring: str.
- :param sort: Sort order. one of ['oldest_first', 'newest_first',
- 'message_id', 'unsorted']
- :type query: str
+ :param sort: Sort order.
+ :type query: alot.db.sort.ORDER
:param exclude_tags: Tags to exclude by default unless included in the
search
:type exclude_tags: set of str
:returns: iterator over thread ids
"""
- # TODO: use a symbolic constant for this
- assert sort in self._sort_orders
-
with self._db_ro() as db:
- sort = self._sort_orders[sort]
exclude_tags = self._exclude_tags | exclude_tags
for t in db.threads(querystring, sort = sort, exclude_tags = exclude_tags):
diff --git a/alot/db/sort.py b/alot/db/sort.py
new file mode 100644
index 00000000..b93c814d
--- /dev/null
+++ b/alot/db/sort.py
@@ -0,0 +1,14 @@
+# Copyright (C) 2012 Anton Khirnov <anton@khirnov.net>
+# This file is released under the GNU GPL, version 3 or a later revision.
+# For further details see the COPYING file
+
+import notmuch2
+
+ORDER = notmuch2.Database.SORT
+
+NAME = {
+ 'oldest_first' : ORDER.OLDEST_FIRST,
+ 'newest_first' : ORDER.NEWEST_FIRST,
+ 'message_id' : ORDER.MESSAGE_ID,
+ 'unsorted' : ORDER.UNSORTED,
+}