diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-12-16 12:13:06 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-12-16 12:13:06 +0000 |
commit | d96dcad3df3e38cf0d1d125e44d3f16e081487b8 (patch) | |
tree | a19710c583ec3cc3ac33322dd02d2aa074eb92f4 /alot/settings | |
parent | c1dbcadbd56e22455d3f1e0c638ce3f03bae89be (diff) |
read configs lazily in SettingsManager
This causes SettingsManager not to read the default configs upon init
when no config paths are passed on.
It is safe because alot.init.main
triggers reading the config files anyway.
This fixes a problem with building the docs on rfd.org due to them not havin configobj available at
build time.
Diffstat (limited to 'alot/settings')
-rw-r--r-- | alot/settings/manager.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/alot/settings/manager.py b/alot/settings/manager.py index dff367b2..30e0afb2 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -28,7 +28,7 @@ DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults') class SettingsManager(object): """Organizes user settings""" - def __init__(self, alot_rc=None, notmuch_rc=None, theme=None): + def __init__(self, alot_rc=None, notmuch_rc=None): """ :param alot_rc: path to alot's config file :type alot_rc: str @@ -39,16 +39,16 @@ class SettingsManager(object): """ self.hooks = None self._mailcaps = mailcap.getcaps() - - theme_path = theme or os.path.join(DEFAULTSPATH, 'default.theme') - self._theme = Theme(theme_path) - bindings_path = os.path.join(DEFAULTSPATH, 'default.bindings') - self._bindings = ConfigObj(bindings_path) self._config = ConfigObj() + self._notmuchconfig = None self._accounts = None self._accountmap = None - self.read_config(alot_rc) - self.read_notmuch_config(notmuch_rc) + bindings_path = os.path.join(DEFAULTSPATH, 'default.bindings') + self._bindings = ConfigObj(bindings_path) + if alot_rc is not None: + self.read_config(alot_rc) + if notmuch_rc is not None: + self.read_notmuch_config(notmuch_rc) def read_notmuch_config(self, path): """parse notmuch's config file from path""" @@ -86,6 +86,7 @@ class SettingsManager(object): themes_dir = os.path.join(configdir, 'alot', 'themes') logging.debug(themes_dir) + # if config contains theme string use that if themestring: if not os.path.isdir(themes_dir): err_msg = 'cannot find theme %s: themes_dir %s is missing' @@ -98,6 +99,11 @@ class SettingsManager(object): err_msg = 'Theme file %s failed validation:\n' raise ConfigError((err_msg % themestring) + e.message) + # if still no theme is set, resort to default + if self._theme is None: + theme_path = os.path.join(DEFAULTSPATH, 'default.theme') + self._theme = Theme(theme_path) + self._accounts = self._parse_accounts(self._config) self._accountmap = self._account_table(self._accounts) |