From 353782e2c89eb88f325dbd3d5fbce48b7e445719 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Mon, 23 Dec 2013 21:34:21 +0100 Subject: [PATCH] local: Add local/data_dir config value. Not in use yet but, needed for future changes planed in this branch. --- docs/ext/local.rst | 5 +++++ mopidy/backends/local/__init__.py | 9 +-------- mopidy/backends/local/actor.py | 8 ++++++++ mopidy/backends/local/ext.conf | 1 + tests/backends/local/events_test.py | 1 + tests/backends/local/playback_test.py | 1 + tests/backends/local/playlists_test.py | 1 + tests/backends/local/tracklist_test.py | 1 + 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/ext/local.rst b/docs/ext/local.rst index cbde826f..43996deb 100644 --- a/docs/ext/local.rst +++ b/docs/ext/local.rst @@ -39,6 +39,11 @@ Configuration values Path to directory with local media files. +.. confval:: local/data_dir + + Path to directory to store local metadata such as libraries and playlists + in. + .. confval:: local/playlists_dir Path to playlists directory with m3u files for local media. diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index dedc868c..5caa6826 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -5,7 +5,6 @@ import os import mopidy from mopidy import config, ext -from mopidy.utils import encoding, path logger = logging.getLogger('mopidy.backends.local') @@ -23,6 +22,7 @@ class Extension(ext.Extension): def get_config_schema(self): schema = super(Extension, self).get_config_schema() schema['media_dir'] = config.Path() + schema['data_dir'] = config.Path() schema['playlists_dir'] = config.Path() schema['tag_cache_file'] = config.Deprecated() schema['scan_timeout'] = config.Integer( @@ -30,13 +30,6 @@ class Extension(ext.Extension): schema['excluded_file_extensions'] = config.List(optional=True) return schema - def validate_environment(self): - try: - path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy/local') - except EnvironmentError as error: - error = encoding.locale_decode(error) - logger.warning('Could not create local data dir: %s', error) - def get_backend_classes(self): from .actor import LocalBackend return [LocalBackend] diff --git a/mopidy/backends/local/actor.py b/mopidy/backends/local/actor.py index a73f627e..78caf39e 100644 --- a/mopidy/backends/local/actor.py +++ b/mopidy/backends/local/actor.py @@ -32,6 +32,14 @@ class LocalBackend(pykka.ThreadingActor, base.Backend): logger.warning('Local media dir %s does not exist.' % self.config['local']['media_dir']) + try: + path.get_or_create_dir(self.config['local']['data_dir']) + except EnvironmentError as error: + logger.warning( + 'Could not create local data dir: %s', + encoding.locale_decode(error)) + + # TODO: replace with data dir? try: path.get_or_create_dir(self.config['local']['playlists_dir']) except EnvironmentError as error: diff --git a/mopidy/backends/local/ext.conf b/mopidy/backends/local/ext.conf index f906a04f..e826a451 100644 --- a/mopidy/backends/local/ext.conf +++ b/mopidy/backends/local/ext.conf @@ -1,6 +1,7 @@ [local] enabled = true media_dir = $XDG_MUSIC_DIR +data_dir = $XDG_DATA_DIR/mopidy/local playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists scan_timeout = 1000 excluded_file_extensions = diff --git a/tests/backends/local/events_test.py b/tests/backends/local/events_test.py index 1e26a68c..2424ed42 100644 --- a/tests/backends/local/events_test.py +++ b/tests/backends/local/events_test.py @@ -17,6 +17,7 @@ class LocalBackendEventsTest(unittest.TestCase): config = { 'local': { 'media_dir': path_to_data_dir(''), + 'data_dir': path_to_data_dir(''), 'playlists_dir': b'', } } diff --git a/tests/backends/local/playback_test.py b/tests/backends/local/playback_test.py index 4c3dd70d..4da420ef 100644 --- a/tests/backends/local/playback_test.py +++ b/tests/backends/local/playback_test.py @@ -22,6 +22,7 @@ class LocalPlaybackProviderTest(unittest.TestCase): config = { 'local': { 'media_dir': path_to_data_dir(''), + 'data_dir': path_to_data_dir(''), 'playlists_dir': b'', } } diff --git a/tests/backends/local/playlists_test.py b/tests/backends/local/playlists_test.py index c02e1d23..447de3f8 100644 --- a/tests/backends/local/playlists_test.py +++ b/tests/backends/local/playlists_test.py @@ -20,6 +20,7 @@ class LocalPlaylistsProviderTest(unittest.TestCase): config = { 'local': { 'media_dir': path_to_data_dir(''), + 'data_dir': path_to_data_dir(''), } } diff --git a/tests/backends/local/tracklist_test.py b/tests/backends/local/tracklist_test.py index c7cfe51f..14bf678d 100644 --- a/tests/backends/local/tracklist_test.py +++ b/tests/backends/local/tracklist_test.py @@ -18,6 +18,7 @@ class LocalTracklistProviderTest(unittest.TestCase): config = { 'local': { 'media_dir': path_to_data_dir(''), + 'data_dir': path_to_data_dir(''), 'playlists_dir': b'', } }