Python xdg.BaseDirectory.xdg_config_home() Examples

The following are 6 code examples of xdg.BaseDirectory.xdg_config_home(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xdg.BaseDirectory , or try the search function .
Example #1
Source File: export.py    From gtg with GNU General Public License v3.0 6 votes vote down vote up
def get_user_dir(key):
    """
    http://www.freedesktop.org/wiki/Software/xdg-user-dirs
     - XDG_DESKTOP_DIR
     - XDG_DOWNLOAD_DIR
     - XDG_TEMPLATES_DIR
     - XDG_PUBLICSHARE_DIR
     - XDG_DOCUMENTS_DIR
     - XDG_MUSIC_DIR
     - XDG_PICTURES_DIR
     - XDG_VIDEOS_DIR

    Taken from FrontBringer
    (distributed under the GNU GPL v3 license),
    courtesy of Jean-François Fortin Tam.
    """
    user_dirs_dirs = os.path.join(xdg_config_home, "user-dirs.dirs")
    user_dirs_dirs = os.path.expanduser(user_dirs_dirs)
    if not os.path.exists(user_dirs_dirs):
        return
    for line in open(user_dirs_dirs, "r"):
        if line.startswith(key):
            return os.path.expandvars(line[len(key) + 2:-2]) 
Example #2
Source File: Desktop.py    From WeatherDesk with GNU General Public License v3.0 6 votes vote down vote up
def get_config_dir(app_name):
    if 'XDG_CONFIG_HOME' in os.environ:
        confighome = os.environ['XDG_CONFIG_HOME']

    elif 'APPDATA' in os.environ:  # On Windows
        confighome = os.environ['APPDATA']

    else:
        try:
            from xdg import BaseDirectory
            confighome = BaseDirectory.xdg_config_home

        except ImportError:  # Most likely a Linux/Unix system anyway
            confighome = os.path.join(os.path.expanduser('~'), '.config')

    configdir = os.path.join(confighome, app_name)

    return configdir 
Example #3
Source File: config_provider.py    From ebook-viewer with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self):
        """
        Manages book files and provides metadata
        """
        self.config = configparser.ConfigParser()
        # Loads configuration from $XDG_CONFIG_HOME/easy-ebook-viewer.conf
        self.__config_path = os.path.expanduser(os.path.join(xdg_config_home, "easy-ebook-viewer.conf"))
        if os.access(self.__config_path, os.W_OK):  # Checks if a config file exists
            # Config file exists, loads it.
            self.config.read(self.__config_path)
        else:
            # Config file doesn't exist, creates new
            self.__create_new_configuration()

        # Validates configuration
        self.__validate_configuration() 
Example #4
Source File: setupConfig.py    From ytmdl with MIT License 5 votes vote down vote up
def __init__(self):
        # The home dir
        self.HOME_DIR = os.path.expanduser('~')

        # The default song dir
        self.SONG_DIR = self._get_music_dir()

        # The temp dir
        self.SONG_TEMP_DIR = os.path.join(self.SONG_DIR, 'ytmdl')

        # The default song quality
        self.SONG_QUALITY = '320'

        # The config path
        self.CONFIG_PATH = os.path.join(xdg_config_home, 'ytmdl') 
Example #5
Source File: test_helpers.py    From fades with GNU General Public License v3.0 5 votes vote down vote up
def test_confdir_xdg(self):
        direct = helpers.get_confdir()
        self.assertEqual(direct, os.path.join(BaseDirectory.xdg_config_home, 'fades')) 
Example #6
Source File: test_helpers.py    From fades with GNU General Public License v3.0 5 votes vote down vote up
def test_confdir_xdg_nonexistant(self):
        with patch("xdg.BaseDirectory") as mock:
            with tempfile.TemporaryDirectory() as dirname:
                mock.xdg_config_home = dirname
                direct = helpers.get_confdir()
                self.assertTrue(os.path.exists(direct))