Install the python library to access freedesktop.org standards
To get the XDG directories from Python you need to install PyXDG. You can install it using APT (depending on your python version) using one of the following packages:
For Python 2.x
sudo apt-get install python-xdg
For Python 3:
sudo apt-get install python3-xdg
You can also install it from PyPI.
XDG Directories
$XDG_DATA_HOME
defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME
is either not set or empty, a default equal to $HOME/.local/share
should be used.
$XDG_CONFIG_HOME
defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME
is either not set or empty, a default equal to $HOME/.config
should be used.
$XDG_DATA_DIRS
defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME
base directory. The directories in $XDG_DATA_DIRS
should be separated with a colon ':'.
If $XDG_DATA_DIRS
is either not set or empty, a value equal to /usr/local/share/:/usr/share/
should be used.
$XDG_CONFIG_DIRS
defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME
base directory. The directories in $XDG_CONFIG_DIRS
should be seperated with a colon ':'.
If $XDG_CONFIG_DIRS
is either not set or empty, a value equal to /etc/xdg
should be used.
Source: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
UPDATE: How to access Ubuntu specific XDG user directories:
The ~/.config/user-dirs.dirs
file will always contain the localize names as the xdg-user-dirs-update tool controls this file, see the dedicated man page section:
The XDG user dirs configuration is stored in the user-dirs.dir
file in the location pointed to by the XDG_CONFIG_HOME
environment variable.
The following python code will allow you to parse the ~/.config/user-dirs.dirs
.
#!/usr/bin/env python
import io
import os
import re
import ConfigParser
from xdg.BaseDirectory import xdg_config_home
config = ConfigParser.RawConfigParser(allow_no_value=True)
f = open(os.path.join(xdg_config_home, "user-dirs.dirs"))
user_config = "[XDG_USER_DIR]\n" + f.read()
f.close()
user_config = re.sub('\$HOME', os.path.expanduser("~"), user_config)
user_config = re.sub('"', '', user_config)
config.readfp(io.BytesIO(user_config))
print config.get("XDG_USER_DIR", "XDG_PICTURES_DIR")