2023-06-28 12:30:22 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from os.path import join, expanduser
|
2023-11-30 19:10:19 +00:00
|
|
|
from typing import NamedTuple
|
2024-04-13 06:49:25 +00:00
|
|
|
from importlib import metadata
|
2017-04-12 14:42:04 +00:00
|
|
|
|
2024-04-13 06:49:25 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
__version__ = metadata.version("toot")
|
|
|
|
except metadata.PackageNotFoundError:
|
|
|
|
__version__ = "0.0.0"
|
2018-01-15 11:19:37 +00:00
|
|
|
|
2023-11-30 19:10:19 +00:00
|
|
|
|
|
|
|
class App(NamedTuple):
|
|
|
|
instance: str
|
|
|
|
base_url: str
|
|
|
|
client_id: str
|
|
|
|
client_secret: str
|
|
|
|
|
|
|
|
|
|
|
|
class User(NamedTuple):
|
|
|
|
instance: str
|
|
|
|
username: str
|
|
|
|
access_token: str
|
|
|
|
|
2017-04-12 14:42:04 +00:00
|
|
|
|
2023-03-07 09:37:03 +00:00
|
|
|
DEFAULT_INSTANCE = 'https://mastodon.social'
|
2017-04-12 14:42:04 +00:00
|
|
|
|
2017-04-19 12:47:30 +00:00
|
|
|
CLIENT_NAME = 'toot - a Mastodon CLI client'
|
2017-04-16 12:14:33 +00:00
|
|
|
CLIENT_WEBSITE = 'https://github.com/ihabunek/toot'
|
2023-06-28 12:30:22 +00:00
|
|
|
|
|
|
|
TOOT_CONFIG_DIR_NAME = "toot"
|
|
|
|
|
|
|
|
|
|
|
|
def get_config_dir():
|
|
|
|
"""Returns the path to toot config directory"""
|
|
|
|
|
|
|
|
# On Windows, store the config in roaming appdata
|
|
|
|
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)
|