From 7b8871b6513623a61a38f7bc0b71da3a79f2e523 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 4 Jul 2018 11:52:49 +0200 Subject: Use pathlib.Path and poezio.xdg to complete themes. --- poezio/core/completions.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'poezio') diff --git a/poezio/core/completions.py b/poezio/core/completions.py index c86e3514..5d6e2e50 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -6,11 +6,13 @@ import logging log = logging.getLogger(__name__) import os +from pathlib import Path from functools import reduce from poezio import common from poezio import pep from poezio import tabs +from poezio import xdg from poezio.common import safeJID from poezio.config import config from poezio.roster import roster @@ -65,20 +67,15 @@ class CompletionCore: def theme(self, the_input): """ Completion for /theme""" themes_dir = config.get('themes_dir') - themes_dir = (themes_dir or os.path.join( - os.environ.get('XDG_DATA_HOME') - or os.path.join(os.environ.get('HOME'), '.local', 'share'), - 'poezio', 'themes')) - themes_dir = os.path.expanduser(themes_dir) + themes_dir = Path(themes_dir).expanduser() if themes_dir else xdg.DATA_HOME / 'themes' try: - names = os.listdir(themes_dir) + theme_files = [ + name.stem for name in themes_dir.iterdir() + if name.suffix == '.py' and name.name != '__init__.py' + ] except OSError: log.error('Completion for /theme failed', exc_info=True) return False - theme_files = [ - name[:-3] for name in names - if name.endswith('.py') and name != '__init__.py' - ] if 'default' not in theme_files: theme_files.append('default') return Completion( -- cgit v1.2.3