Better handling of standard paths (#187)

This commit is contained in:
Aleksana
2024-08-04 04:07:14 +08:00
committed by GitHub
parent 131e8fb6be
commit 5a0d1ed408
5 changed files with 43 additions and 18 deletions

22
src/internal.py Normal file
View File

@@ -0,0 +1,22 @@
import os
app_id = "com.jeffser.Alpaca"
in_flatpak = True if os.getenv("FLATPAK_ID") else False
def get_xdg_home(env, default):
if in_flatpak:
return os.getenv(env)
else:
base = os.getenv(env) or os.path.expanduser(default)
path = os.path.join(base, app_id)
if not os.path.exists(path):
os.makedirs(path)
return path
data_dir = get_xdg_home("XDG_DATA_HOME", "~/.local/share")
config_dir = get_xdg_home("XDG_CONFIG_HOME", "~/.config")
cache_dir = get_xdg_home("XDG_CACHE_HOME", "~/.cache")
source_dir = os.path.abspath(os.path.dirname(__file__))