From f0ad4b348b9cb559a9b45882187514a063bd627f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 4 Jul 2018 11:56:42 +0200 Subject: Use pathlib.Path and poezio.xdg to load themes. --- poezio/theming.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'poezio/theming.py') diff --git a/poezio/theming.py b/poezio/theming.py index 5cdd89ae..0cf0f27d 100755 --- a/poezio/theming.py +++ b/poezio/theming.py @@ -74,8 +74,9 @@ except ImportError: import curses import functools import os +from pathlib import Path from os import path -from poezio import colors +from poezio import colors, xdg from importlib import machinery finder = machinery.PathFinder() @@ -493,18 +494,12 @@ def update_themes_dir(option=None, value=None): load_path.append(default_dir) # import from the user-defined prefs - themes_dir = path.expanduser( - value or config.get('themes_dir') or path.join( - os.environ.get('XDG_DATA_HOME') - or path.join(os.environ.get('HOME'), '.local', 'share'), 'poezio', - 'themes')) + themes_dir = config.get('themes_dir') + themes_dir = Path(themes_dir).expanduser() if themes_dir else xdg.DATA_HOME / 'themes' try: - os.makedirs(themes_dir) - except OSError as e: - if e.errno != 17: - log.error('Unable to create the themes dir (%s)', themes_dir) - else: - load_path.append(themes_dir) + themes_dir.mkdir(parents=True, exist_ok=True) + except OSError: + log.exception('Unable to create the themes dir (%s):', themes_dir) else: load_path.append(themes_dir) -- cgit v1.2.3