-
Notifications
You must be signed in to change notification settings - Fork 5
/
xdg.py
34 lines (23 loc) · 1 KB
/
xdg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2019-2021 Patryk Obara <[email protected]>
"""
XDG Base Directories
https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
"""
import os
DATA_HOME = os.environ.get('XDG_DATA_HOME') or \
os.path.expanduser('~/.local/share')
CONF_HOME = os.environ.get('XDG_CONFIG_HOME') or \
os.path.expanduser('~/.config')
CACHE_HOME = os.environ.get('XDG_CACHE_HOME') or \
os.path.expanduser('~/.cache')
DATA_DIRS = os.environ.get('XDG_DATA_DIRS', '/usr/share').split(os.pathsep)
def get_data_dirs(include_data_home=True):
"""Return all XDG_DATA_DIRS, optionally including XDG_DATA_HOME."""
if include_data_home and DATA_HOME not in DATA_DIRS:
return [DATA_HOME] + DATA_DIRS
return DATA_DIRS
def cached_file(name):
"""Obtain path to cached file in application specific dir."""
os.makedirs(CACHE_HOME + '/boxtron', exist_ok=True)
return os.path.join(CACHE_HOME, 'boxtron', name)