bumblebee-status/bumblebee_status/modules/contrib/notmuch_count.py

52 lines
1.3 KiB
Python
Raw Permalink Normal View History

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/)
contributed by `abdoulayeYATERA <https://github.com/abdoulayeYATERA>`_ - many thanks!
2020-04-18 16:35:45 +02:00
"""
import os
import core.module
import core.widget
2020-04-18 16:35:45 +02:00
import util.cli
2020-04-18 16:35:45 +02:00
class Module(core.module.Module):
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.output))
2020-04-18 16:35:45 +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):
return self.__notmuch_count
2020-04-18 16:35:45 +02:00
def state(self, widgets):
if self.__notmuch_count == 0:
return "empty"
return "items"
2020-04-18 16:35:45 +02:00
def update(self):
2020-04-18 16:35:45 +02:00
try:
self.__notmuch_count = util.cli.execute(
"notmuch count {}".format(self.__notmuch_count_query)
).strip()
2020-04-18 16:35:45 +02:00
except Exception:
self.__notmuch_count = "n/a"
2020-04-18 16:35:45 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4