diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-07-04 11:52:49 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-07-04 12:07:31 +0200 |
commit | 7b8871b6513623a61a38f7bc0b71da3a79f2e523 (patch) | |
tree | 82598c0899359feb2fa5b9cbbe71a0cfb4f52e6b | |
parent | da12fe7d6aa9ee9a710e914185a45f843180e42e (diff) | |
download | poezio-7b8871b6513623a61a38f7bc0b71da3a79f2e523.tar.gz poezio-7b8871b6513623a61a38f7bc0b71da3a79f2e523.tar.bz2 poezio-7b8871b6513623a61a38f7bc0b71da3a79f2e523.tar.xz poezio-7b8871b6513623a61a38f7bc0b71da3a79f2e523.zip |
Use pathlib.Path and poezio.xdg to complete themes.
-rw-r--r-- | poezio/core/completions.py | 17 |
1 files changed, 7 insertions, 10 deletions
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( |