-
Notifications
You must be signed in to change notification settings - Fork 3
/
xdg.py
32 lines (22 loc) · 934 Bytes
/
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
#!/usr/bin/python3
"""
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 + '/roberta', exist_ok=True)
return os.path.join(CACHE_HOME, 'roberta', name)