mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-29 04:35:54 -04:00
Improve config dir location
On Windows store config in roaming appdata.
This commit is contained in:
parent
130ef9a608
commit
5343319333
@ -1,25 +1,39 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from os.path import dirname
|
from os.path import dirname, join, expanduser
|
||||||
|
|
||||||
from toot import User, App
|
from toot import User, App
|
||||||
from toot.exceptions import ConsoleError
|
from toot.exceptions import ConsoleError
|
||||||
from toot.output import print_out
|
from toot.output import print_out
|
||||||
|
|
||||||
|
|
||||||
def get_config_file_path():
|
TOOT_CONFIG_DIR_NAME = "toot"
|
||||||
"""Returns the path to toot config file
|
TOOT_CONFIG_FILE_NAME = "config.json"
|
||||||
|
|
||||||
Attempts to locate config home dir from XDG_CONFIG_HOME env variable.
|
|
||||||
See: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
|
def get_config_dir():
|
||||||
If not found, defaults to `~/.config`.
|
"""Returns the path to toot config directory"""
|
||||||
"""
|
|
||||||
config_dir = os.getenv('XDG_CONFIG_HOME', '~/.config')
|
# On Windows, store the config in roaming appdata
|
||||||
return os.path.expanduser(config_dir + '/toot/config.json')
|
if sys.platform == "win32" and "APPDATA" in os.environ:
|
||||||
|
return join(os.getenv("APPDATA"), TOOT_CONFIG_DIR_NAME)
|
||||||
|
|
||||||
|
# Respect XDG_CONFIG_HOME env variable if set
|
||||||
|
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||||
|
if "XDG_CONFIG_HOME" in os.environ:
|
||||||
|
config_home = expanduser(os.environ["XDG_CONFIG_HOME"])
|
||||||
|
return join(config_home, TOOT_CONFIG_DIR_NAME)
|
||||||
|
|
||||||
|
# Default to ~/.config/toot/
|
||||||
|
return join(expanduser("~"), ".config", TOOT_CONFIG_DIR_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
def get_config_file_path():
|
||||||
|
"""Returns the path to toot config file."""
|
||||||
|
return join(get_config_dir(), TOOT_CONFIG_FILE_NAME)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FILE = get_config_file_path()
|
CONFIG_FILE = get_config_file_path()
|
||||||
|
Loading…
Reference in New Issue
Block a user