示例#1
0
def test_user_dirs_when_no_dirs_file(environ, tmpdir):
    os.environ['XDG_CONFIG_HOME'] = str(tmpdir)

    result = xdg.get_dirs()

    assert 'XDG_MUSIC_DIR' not in result
    assert 'XDG_DOWNLOAD_DIR' not in result
示例#2
0
def test_user_dirs_when_no_dirs_file(environ, tmpdir):
    os.environ['XDG_CONFIG_HOME'] = str(tmpdir)

    result = xdg.get_dirs()

    assert 'XDG_MUSIC_DIR' not in result
    assert 'XDG_DOWNLOAD_DIR' not in result
示例#3
0
def test_user_dirs(environ, tmpdir):
    os.environ['XDG_CONFIG_HOME'] = str(tmpdir)

    with open(os.path.join(str(tmpdir), 'user-dirs.dirs'), 'wb') as fh:
        fh.write('# Some comments\n')
        fh.write('XDG_MUSIC_DIR="$HOME/Music2"\n')

    result = xdg.get_dirs()

    assert result['XDG_MUSIC_DIR'] == os.path.expanduser(b'~/Music2')
    assert 'XDG_DOWNLOAD_DIR' not in result
示例#4
0
def test_user_dirs(environ, tmpdir):
    os.environ["XDG_CONFIG_HOME"] = str(tmpdir)

    with open(os.path.join(str(tmpdir), "user-dirs.dirs"), "wb") as fh:
        fh.write(b"# Some comments\n")
        fh.write(b'XDG_MUSIC_DIR="$HOME/Music2"\n')

    result = xdg.get_dirs()

    assert result["XDG_MUSIC_DIR"] == pathlib.Path("~/Music2").expanduser()
    assert "XDG_DOWNLOAD_DIR" not in result
示例#5
0
import logging
import os
import stat
import string
import threading
import urllib
import urlparse

from mopidy import compat, exceptions
from mopidy.compat import queue
from mopidy.internal import encoding, xdg

logger = logging.getLogger(__name__)

XDG_DIRS = xdg.get_dirs()


def get_or_create_dir(dir_path):
    if not isinstance(dir_path, bytes):
        raise ValueError('Path is not a bytestring.')
    dir_path = expand_path(dir_path)
    if os.path.isfile(dir_path):
        raise OSError('A file with the same name as the desired dir, '
                      '"%s", already exists.' % dir_path)
    elif not os.path.isdir(dir_path):
        logger.info('Creating dir %s', dir_path)
        os.makedirs(dir_path, 0o755)
    return dir_path

示例#6
0
def test_cache_dir_from_env(environ):
    os.environ["XDG_CACHE_HOME"] = "/foo/bar"

    assert xdg.get_dirs()["XDG_CACHE_DIR"] == pathlib.Path("/foo/bar")
示例#7
0
def test_data_dir_from_env(environ):
    os.environ['XDG_DATA_HOME'] = b'/foo/bar'

    assert xdg.get_dirs()['XDG_DATA_DIR'] == b'/foo/bar'
    assert type(xdg.get_dirs()['XDG_DATA_DIR']) == bytes
示例#8
0
def test_config_dir_from_env(environ):
    os.environ['XDG_CONFIG_HOME'] = b'/foo/bar'

    assert xdg.get_dirs()['XDG_CONFIG_DIR'] == b'/foo/bar'
    assert type(xdg.get_dirs()['XDG_CONFIG_DIR']) == bytes
示例#9
0
def test_cache_dir_from_env(environ):
    os.environ['XDG_CACHE_HOME'] = b'/foo/bar'

    assert xdg.get_dirs()['XDG_CACHE_DIR'] == b'/foo/bar'
    assert type(xdg.get_dirs()['XDG_CACHE_DIR']) == bytes
示例#10
0
def test_cache_dir_from_env(environ):
    os.environ['XDG_CACHE_HOME'] = '/foo/bar'

    assert xdg.get_dirs()['XDG_CACHE_DIR'] == '/foo/bar'
示例#11
0
def test_cache_dir_default(environ):
    assert xdg.get_dirs()['XDG_CACHE_DIR'] == os.path.expanduser(b'~/.cache')
示例#12
0
def test_data_dir_from_env(environ):
    os.environ["XDG_DATA_HOME"] = "/foo/bar"

    assert xdg.get_dirs()["XDG_DATA_DIR"] == pathlib.Path("/foo/bar")
示例#13
0
def test_data_dir_default(environ):
    assert xdg.get_dirs()["XDG_DATA_DIR"] == (
        pathlib.Path("~/.local/share").expanduser()
    )
示例#14
0
def test_config_dir_from_env(environ):
    os.environ["XDG_CONFIG_HOME"] = "/foo/bar"

    assert xdg.get_dirs()["XDG_CONFIG_DIR"] == pathlib.Path("/foo/bar")
示例#15
0
def test_config_dir_default(environ):
    assert xdg.get_dirs()["XDG_CONFIG_DIR"] == (
        pathlib.Path("~/.config").expanduser()
    )
示例#16
0
文件: path.py 项目: Afolabi28/mopidy
import logging
import os
import stat
import string
import threading

from mopidy import compat, exceptions
from mopidy.compat import queue, urllib
from mopidy.internal import encoding, xdg


logger = logging.getLogger(__name__)


XDG_DIRS = xdg.get_dirs()


def get_or_create_dir(dir_path):
    if not isinstance(dir_path, bytes):
        raise ValueError('Path is not a bytestring.')
    dir_path = expand_path(dir_path)
    if os.path.isfile(dir_path):
        raise OSError(
            'A file with the same name as the desired dir, '
            '"%s", already exists.' % dir_path)
    elif not os.path.isdir(dir_path):
        logger.info('Creating dir %s', dir_path)
        os.makedirs(dir_path, 0o755)
    return dir_path
示例#17
0
def test_cache_dir_default(environ):
    assert xdg.get_dirs()['XDG_CACHE_DIR'] == os.path.expanduser(b'~/.cache')
示例#18
0
def test_config_dir_default(environ):
    assert xdg.get_dirs()['XDG_CONFIG_DIR'] == os.path.expanduser(b'~/.config')
示例#19
0
def test_config_dir_default(environ):
    assert xdg.get_dirs()['XDG_CONFIG_DIR'] == os.path.expanduser(b'~/.config')
示例#20
0
def test_config_dir_from_env(environ):
    os.environ['XDG_CONFIG_HOME'] = '/foo/bar'

    assert xdg.get_dirs()['XDG_CONFIG_DIR'] == '/foo/bar'
示例#21
0
def test_data_dir_default(environ):
    assert xdg.get_dirs()['XDG_DATA_DIR'] == os.path.expanduser(
        b'~/.local/share')
示例#22
0
def test_data_dir_default(environ):
    assert xdg.get_dirs()['XDG_DATA_DIR'] == os.path.expanduser(
        b'~/.local/share')
示例#23
0
def test_data_dir_from_env(environ):
    os.environ['XDG_DATA_HOME'] = '/foo/bar'

    assert xdg.get_dirs()['XDG_DATA_DIR'] == '/foo/bar'
示例#24
0
def test_cache_dir_default(environ):
    assert xdg.get_dirs()["XDG_CACHE_DIR"] == (
        pathlib.Path("~/.cache").expanduser()
    )