Respect XDG_CONFIG_HOME env variable

to locate configuration home directory.

fixes #12
pull/48/head
Ivan Habunek 2018-01-14 15:28:05 +01:00
rodzic 536328f56b
commit 455e531194
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: CDBD63C43A30BB95
3 zmienionych plików z 34 dodań i 5 usunięć

Wyświetl plik

@ -1,6 +1,12 @@
Changelog
---------
**0.17.0 (TBA)**
* Changed configuration file format to allow switching between multiple logged
in accounts (#32)
* Respect XDG_CONFIG_HOME environment variable to locate config home (#12)
**0.16.2 (2018-01-02)**
* No changes, pushed to fix a packaging issue

Wyświetl plik

@ -1,3 +1,4 @@
import os
import pytest
from toot import User, App, config
@ -119,3 +120,19 @@ def test_delete_app(sample_config):
config.delete_app.__wrapped__(sample_config, app)
assert 'foo.social' not in sample_config['apps']
assert len(sample_config['apps']) == app_count - 1
def test_get_config_file_path():
fn = config.get_config_file_path
os.unsetenv('XDG_CONFIG_HOME')
assert fn() == os.path.expanduser('~/.config/toot/config.json')
os.environ['XDG_CONFIG_HOME'] = '/foo/bar/config'
assert fn() == '/foo/bar/config/toot/config.json'
os.environ['XDG_CONFIG_HOME'] = '~/foo/config'
assert fn() == os.path.expanduser('~/foo/config/toot/config.json')

Wyświetl plik

@ -11,12 +11,18 @@ from toot.exceptions import ConsoleError
from toot.output import print_out
# The file holding toot configuration
CONFIG_FILE = os.environ['HOME'] + '/.config/toot/config.json'
def get_config_file_path():
return CONFIG_FILE
"""Returns the path to toot config file
Attempts to locate config home dir from XDG_CONFIG_HOME env variable.
See: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
If not found, defaults to `~/.config`.
"""
config_dir = os.getenv('XDG_CONFIG_HOME', '~/.config')
return os.path.expanduser(config_dir + '/toot/config.json')
CONFIG_FILE = get_config_file_path()
def user_id(user):