예제 #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
파일: test_xdg.py 프로젝트: zwl1671/mopidy
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
파일: test_xdg.py 프로젝트: zwl1671/mopidy
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
파일: test_xdg.py 프로젝트: zwl1671/mopidy
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
파일: test_xdg.py 프로젝트: zwl1671/mopidy
def test_data_dir_default(environ):
    assert xdg.get_dirs()["XDG_DATA_DIR"] == (
        pathlib.Path("~/.local/share").expanduser()
    )
예제 #14
0
파일: test_xdg.py 프로젝트: zwl1671/mopidy
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
파일: test_xdg.py 프로젝트: zwl1671/mopidy
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
파일: test_xdg.py 프로젝트: zwl1671/mopidy
def test_cache_dir_default(environ):
    assert xdg.get_dirs()["XDG_CACHE_DIR"] == (
        pathlib.Path("~/.cache").expanduser()
    )