diff options
-rw-r--r-- | alot/__main__.py | 11 | ||||
-rw-r--r-- | alot/settings/manager.py | 59 |
2 files changed, 28 insertions, 42 deletions
diff --git a/alot/__main__.py b/alot/__main__.py index b46985cb..1000f2c9 100644 --- a/alot/__main__.py +++ b/alot/__main__.py @@ -90,20 +90,17 @@ def main(): filemode='w', format=logformat) # locate alot config files + cpath = options.config if options.config is None: xdg_dir = get_xdg_env('XDG_CONFIG_HOME', os.path.expanduser('~/.config')) alotconfig = os.path.join(xdg_dir, 'alot', 'config') if os.path.exists(alotconfig): - settings.alot_rc_path = alotconfig - else: - settings.alot_rc_path = options.config - - settings.notmuch_rc_path = options.notmuch_config + cpath = alotconfig try: - settings.read_config() - settings.read_notmuch_config() + settings.read_config(cpath) + settings.read_notmuch_config(options.notmuch_config) except (ConfigError, OSError, IOError) as e: print('Error when parsing a config file. ' 'See log for potential details.') diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 1e275aeb..d1f57083 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -29,55 +29,46 @@ DATA_DIRS = get_xdg_env('XDG_DATA_DIRS', class SettingsManager(object): """Organizes user settings""" - def __init__(self, alot_rc=None, notmuch_rc=None): - """ - :param alot_rc: path to alot's config file - :type alot_rc: str - :param notmuch_rc: path to notmuch's config file - :type notmuch_rc: str - """ - assert alot_rc is None or (isinstance(alot_rc, str) and - os.path.exists(alot_rc)) - assert notmuch_rc is None or (isinstance(notmuch_rc, str) and - os.path.exists(notmuch_rc)) + def __init__(self): self.hooks = None self._mailcaps = mailcap.getcaps() self._notmuchconfig = None self._theme = None self._accounts = None self._accountmap = None - self.alot_rc_path = alot_rc - self.notmuch_rc_path = notmuch_rc self._notmuchconfig = None self._config = ConfigObj() self._bindings = None - self.reload() def reload(self): - """Reload All configurations. - - This first resets all configs to default (in case an overwritten - binding is removed from the user config), then reloads the notmuch - config, and finally reads the alot config. + """Reload notmuch and alot config files""" + self.read_notmuch_config(self._notmuchconfig.filename) + self.read_config(self._config.filename) - Implementation Detail: this is the same code called by the constructor - to set bindings at alot startup. + def read_notmuch_config(self, path): """ + parse notmuch's config file + :param path: path to notmuch's config file + :type path: str + """ + spec = os.path.join(DEFAULTSPATH, 'notmuch.rc.spec') + self._notmuchconfig = read_config(path, spec) + + def _update_bindings(self, newbindings): + assert isinstance(newbindings, Section) + self._bindings = ConfigObj(os.path.join(DEFAULTSPATH, 'default.bindings')) - self.read_notmuch_config() - self.read_config() - - def read_notmuch_config(self): - """parse notmuch's config file from path""" - spec = os.path.join(DEFAULTSPATH, 'notmuch.rc.spec') - self._notmuchconfig = read_config(self.notmuch_rc_path, spec) + self._bindings.merge(newbindings) - def read_config(self): - """parse alot's config file from path""" + def read_config(self, path): + """ + parse alot's config file + :param path: path to alot's config file + :type path: str + """ spec = os.path.join(DEFAULTSPATH, 'alot.rc.spec') - newconfig = read_config( - self.alot_rc_path, spec, report_extra=True, checks={ + newconfig = read_config(path, spec, report_extra=True, checks={ 'mail_container': checks.mail_container, 'force_list': checks.force_list, 'align': checks.align_mode, @@ -94,9 +85,7 @@ class SettingsManager(object): except: logging.exception('unable to load hooks file:%s', hooks_path) if 'bindings' in newconfig: - newbindings = newconfig['bindings'] - if isinstance(newbindings, Section): - self._bindings.merge(newbindings) + self._update_bindings(newconfig['bindings']) tempdir = self._config.get('template_dir') logging.debug('template directory: `%s`' % tempdir) |