Use pathlib.Path and poezio.xdg to load themes.

This commit is contained in:
Emmanuel Gil Peyrot 2018-07-04 11:56:42 +02:00
parent 7b8871b651
commit f0ad4b348b

View file

@ -74,8 +74,9 @@ except ImportError:
import curses import curses
import functools import functools
import os import os
from pathlib import Path
from os import path from os import path
from poezio import colors from poezio import colors, xdg
from importlib import machinery from importlib import machinery
finder = machinery.PathFinder() finder = machinery.PathFinder()
@ -493,18 +494,12 @@ def update_themes_dir(option=None, value=None):
load_path.append(default_dir) load_path.append(default_dir)
# import from the user-defined prefs # import from the user-defined prefs
themes_dir = path.expanduser( themes_dir = config.get('themes_dir')
value or config.get('themes_dir') or path.join( themes_dir = Path(themes_dir).expanduser() if themes_dir else xdg.DATA_HOME / 'themes'
os.environ.get('XDG_DATA_HOME')
or path.join(os.environ.get('HOME'), '.local', 'share'), 'poezio',
'themes'))
try: try:
os.makedirs(themes_dir) themes_dir.mkdir(parents=True, exist_ok=True)
except OSError as e: except OSError:
if e.errno != 17: log.exception('Unable to create the themes dir (%s):', themes_dir)
log.error('Unable to create the themes dir (%s)', themes_dir)
else:
load_path.append(themes_dir)
else: else:
load_path.append(themes_dir) load_path.append(themes_dir)