2020-04-18 16:35:45 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays the result of a notmuch count query
|
2020-04-18 16:36:14 +02:00
|
|
|
default : unread emails which path do not contained 'Trash' (notmuch count 'tag:unread AND NOT path:/.*Trash.*/')
|
2020-04-18 16:35:45 +02:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* notmuch_count.query: notmuch count query to show result
|
|
|
|
|
|
|
|
Errors:
|
|
|
|
if the notmuch query failed, the shown value is -1
|
|
|
|
|
|
|
|
Dependencies:
|
|
|
|
notmuch (https://notmuchmail.org/)
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
contributed by `abdoulayeYATERA <https://github.com/abdoulayeYATERA>`_ - many thanks!
|
2020-04-18 16:35:45 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2020-04-18 16:41:30 +02:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
2020-04-18 16:35:45 +02:00
|
|
|
|
2020-04-18 16:41:30 +02:00
|
|
|
import util.cli
|
2020-04-18 16:35:45 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-18 16:41:30 +02:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.output))
|
2020-04-18 16:35:45 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__notmuch_count_query = self.parameter(
|
|
|
|
"query", "tag:unread AND NOT path:/.*Trash.*/"
|
|
|
|
)
|
2020-04-18 16:35:45 +02:00
|
|
|
|
|
|
|
def output(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
return self.__notmuch_count
|
2020-04-18 16:35:45 +02:00
|
|
|
|
|
|
|
def state(self, widgets):
|
2020-04-18 16:41:30 +02:00
|
|
|
if self.__notmuch_count == 0:
|
2020-05-03 11:15:52 +02:00
|
|
|
return "empty"
|
|
|
|
return "items"
|
2020-04-18 16:35:45 +02:00
|
|
|
|
2020-04-18 16:41:30 +02:00
|
|
|
def update(self):
|
2020-04-18 16:35:45 +02:00
|
|
|
try:
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__notmuch_count = util.cli.execute(
|
|
|
|
"notmuch count {}".format(self.__notmuch_count_query)
|
|
|
|
).strip()
|
2020-04-18 16:35:45 +02:00
|
|
|
except Exception:
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__notmuch_count = "n/a"
|
|
|
|
|
2020-04-18 16:35:45 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|