diff options
author | Julian Mehne <julian.mehne@posteo.de> | 2017-12-06 20:55:11 +0100 |
---|---|---|
committer | Julian Mehne <julian.mehne@posteo.de> | 2018-01-07 22:38:28 +0100 |
commit | 04bd1ed039cd17ddbea9785eee46cd25356b3eaa (patch) | |
tree | 3e1ddaaa6845ce709a940786b5ac8e9e11140cd2 /alot/settings | |
parent | 2ef957b4d9626eb1b1ff6d011823ac92f0eb917d (diff) |
Clean up theme finder logic.
- Replace directory check with file check - we only check for a single
file, no need to check for existende of the directory separately. Also,
this way we can distinguish between file validation error and file
not found.
- Be consistent: we stop iterating, if we find a file and it can be
parsed. If we can't parse it, stop iterating as well, don't keep looking
for the file.
Diffstat (limited to 'alot/settings')
-rw-r--r-- | alot/settings/manager.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 98d534fb..10a441ed 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -116,22 +116,19 @@ class SettingsManager(object): # tl/dr; If the loop loads a theme it breaks. If it doesn't break, # then it raises a ConfigError. for dir_ in itertools.chain([themes_dir], data_dirs): - if not os.path.isdir(dir_): - logging.warning( - 'cannot find theme %s: themes_dir %s is missing', - themestring, dir_) + theme_path = os.path.join(dir_, themestring) + if not os.path.exists(os.path.expanduser(theme_path)): + logging.warning('Theme `%s` does not exist.', theme_path) else: - theme_path = os.path.join(dir_, themestring) try: self._theme = Theme(theme_path) except ConfigError as e: - logging.warning( - 'Theme file %s failed validation: %s', - themestring, e) + raise ConfigError('Theme file `%s` failed ' + 'validation:\n%s' % (theme_path, e)) else: break else: - raise ConfigError('Cannot load theme {}, see log for more ' + raise ConfigError('Could not find theme {}, see log for more ' 'information'.format(themestring)) # if still no theme is set, resort to default |