Respect XDG_CONFIG_HOME env variable - toot - Unnamed repository; edit this file 'description' to name the repository.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 455e531194a896490905a4e78c3a3dff10eb300b
(DIR) parent 536328f56b3050e966ff44f3127e8270cad61dd6
(HTM) Author: Ivan Habunek <ivan@habunek.com>
Date: Sun, 14 Jan 2018 15:28:05 +0100
Respect XDG_CONFIG_HOME env variable
to locate configuration home directory.
fixes #12
Diffstat:
CHANGELOG.md | 6 ++++++
tests/test_config.py | 17 +++++++++++++++++
toot/config.py | 14 ++++++++++----
3 files changed, 33 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -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
(DIR) diff --git a/tests/test_config.py b/tests/test_config.py
@@ -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')
(DIR) diff --git a/toot/config.py b/toot/config.py
@@ -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():
+ """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')
-def get_config_file_path():
- return CONFIG_FILE
+CONFIG_FILE = get_config_file_path()
def user_id(user):