From 914e495c2200cbfe3d4b4ac8b07feb64b663e883 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Thu, 28 Aug 2014 23:14:07 +0200 Subject: [PATCH] This patch allows the notmuch backend to retrieve the notmuch database path from the notmuch configuration file in case no "db_path" argument is passed to the Notmuch constructor. In such a case, i3pystatus will try to load the file designed by the environment variable NOTMUCH_CONFIG and "~/.notmuch_config". and retrieve the value "path" of the section [database]. --- i3pystatus/mail/notmuchmail.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/i3pystatus/mail/notmuchmail.py b/i3pystatus/mail/notmuchmail.py index 054e91e..725b03f 100644 --- a/i3pystatus/mail/notmuchmail.py +++ b/i3pystatus/mail/notmuchmail.py @@ -4,7 +4,8 @@ # note that this needs the notmuch python bindings. For more info see: # http://notmuchmail.org/howto/#index4h2 import notmuch - +import configparser +import os from i3pystatus.mail import Backend @@ -15,9 +16,27 @@ class Notmuch(Backend): and "unread" """ - settings = required = ("db_path",) + settings = ( + ("db_path","Path to the directory of your notmuch database"), + ) + + db_path = None; def init(self): + + if not self.db_path: + defaultConfigFilename= os.path.expanduser("~/.notmuch-config") + config = configparser.RawConfigParser() + + # read tries to read and returns successfully read filenames + successful = config.read( [ + os.environ.get("NOTMUCH_CONFIG",defaultConfigFilename), + defaultConfigFilename + ] + ) + + self.db_path = config.get("database","path") + self.db = notmuch.Database(self.db_path) @property