From 3339b79c1e269d2706427bbda8153deab56d4a28 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 8 Apr 2013 20:55:27 +0200 Subject: [PATCH] local: Rename 'music_path' to 'music_dir', 'playlist_path' to 'playlists_dir' --- mopidy/backends/local/__init__.py | 14 +++++++------- mopidy/backends/local/library.py | 7 +++---- mopidy/backends/local/playlists.py | 22 +++++++++++----------- mopidy/scanner.py | 6 +++--- tests/backends/local/events_test.py | 4 ++-- tests/backends/local/library_test.py | 4 ++-- tests/backends/local/playback_test.py | 4 ++-- tests/backends/local/playlists_test.py | 24 ++++++++++++------------ tests/backends/local/tracklist_test.py | 4 ++-- 9 files changed, 44 insertions(+), 45 deletions(-) diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 54a1c7a4..abd3eab6 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -11,13 +11,13 @@ default_config = """ # If the local extension should be enabled or not enabled = true -# Path to folder with local music -music_path = $XDG_MUSIC_DIR +# Path to directory with local media files +media_dir = $XDG_MUSIC_DIR -# Path to playlist folder with m3u files for local music -playlist_path = $XDG_DATA_DIR/mopidy/playlists +# Path to playlists directory with m3u files for local media +playlists_dir = $XDG_DATA_DIR/mopidy/playlists -# Path to tag cache for local music +# Path to tag cache for local media tag_cache_file = $XDG_DATA_DIR/mopidy/tag_cache """ @@ -55,8 +55,8 @@ class Extension(ext.Extension): def get_config_schema(self): schema = config.ExtensionConfigSchema() - schema['music_path'] = config.Path() - schema['playlist_path'] = config.Path() + schema['media_dir'] = config.Path() + schema['playlists_dir'] = config.Path() schema['tag_cache_file'] = config.Path() return schema diff --git a/mopidy/backends/local/library.py b/mopidy/backends/local/library.py index 2b1c93f7..a76ce594 100644 --- a/mopidy/backends/local/library.py +++ b/mopidy/backends/local/library.py @@ -14,17 +14,16 @@ class LocalLibraryProvider(base.BaseLibraryProvider): def __init__(self, *args, **kwargs): super(LocalLibraryProvider, self).__init__(*args, **kwargs) self._uri_mapping = {} - self._music_path = self.backend.config['local']['music_path'] - self._playlist_path = self.backend.config['local']['playlist_path'] + self._media_dir = self.backend.config['local']['media_dir'] self._tag_cache_file = self.backend.config['local']['tag_cache_file'] self.refresh() def refresh(self, uri=None): - tracks = parse_mpd_tag_cache(self._tag_cache_file, self._music_path) + tracks = parse_mpd_tag_cache(self._tag_cache_file, self._media_dir) logger.info( 'Loading tracks from %s using %s', - self._music_path, self._tag_cache_file) + self._media_dir, self._tag_cache_file) for track in tracks: self._uri_mapping[track.uri] = track diff --git a/mopidy/backends/local/playlists.py b/mopidy/backends/local/playlists.py index 063d044d..3b9e1d73 100644 --- a/mopidy/backends/local/playlists.py +++ b/mopidy/backends/local/playlists.py @@ -18,8 +18,8 @@ logger = logging.getLogger('mopidy.backends.local') class LocalPlaylistsProvider(base.BasePlaylistsProvider): def __init__(self, *args, **kwargs): super(LocalPlaylistsProvider, self).__init__(*args, **kwargs) - self._music_path = self.backend.config['local']['music_path'] - self._playlist_path = self.backend.config['local']['playlist_path'] + self._media_dir = self.backend.config['local']['media_dir'] + self._playlists_dir = self.backend.config['local']['playlists_dir'] self.refresh() def create(self, name): @@ -42,16 +42,16 @@ class LocalPlaylistsProvider(base.BasePlaylistsProvider): return playlist def refresh(self): - logger.info('Loading playlists from %s', self._playlist_path) + logger.info('Loading playlists from %s', self._playlists_dir) playlists = [] - for m3u in glob.glob(os.path.join(self._playlist_path, '*.m3u')): + for m3u in glob.glob(os.path.join(self._playlists_dir, '*.m3u')): uri = path.path_to_uri(m3u) name = os.path.splitext(os.path.basename(m3u))[0] tracks = [] - for track_uri in parse_m3u(m3u, self._music_path): + for track_uri in parse_m3u(m3u, self._media_dir): try: # TODO We must use core.library.lookup() to support tracks # from other backends @@ -86,13 +86,13 @@ class LocalPlaylistsProvider(base.BasePlaylistsProvider): def _get_m3u_path(self, name): name = formatting.slugify(name) - file_path = os.path.join(self._playlist_path, name + '.m3u') - path.check_file_path_is_inside_base_dir(file_path, self._playlist_path) + file_path = os.path.join(self._playlists_dir, name + '.m3u') + path.check_file_path_is_inside_base_dir(file_path, self._playlists_dir) return file_path def _save_m3u(self, playlist): file_path = path.uri_to_path(playlist.uri) - path.check_file_path_is_inside_base_dir(file_path, self._playlist_path) + path.check_file_path_is_inside_base_dir(file_path, self._playlists_dir) with open(file_path, 'w') as file_handle: for track in playlist.tracks: if track.uri.startswith('file://'): @@ -103,18 +103,18 @@ class LocalPlaylistsProvider(base.BasePlaylistsProvider): def _delete_m3u(self, uri): file_path = path.uri_to_path(uri) - path.check_file_path_is_inside_base_dir(file_path, self._playlist_path) + path.check_file_path_is_inside_base_dir(file_path, self._playlists_dir) if os.path.exists(file_path): os.remove(file_path) def _rename_m3u(self, playlist): src_file_path = path.uri_to_path(playlist.uri) path.check_file_path_is_inside_base_dir( - src_file_path, self._playlist_path) + src_file_path, self._playlists_dir) dst_file_path = self._get_m3u_path(playlist.name) path.check_file_path_is_inside_base_dir( - dst_file_path, self._playlist_path) + dst_file_path, self._playlists_dir) shutil.move(src_file_path, dst_file_path) diff --git a/mopidy/scanner.py b/mopidy/scanner.py index 364828f4..0f87a4d1 100644 --- a/mopidy/scanner.py +++ b/mopidy/scanner.py @@ -57,9 +57,9 @@ def main(): logging.warning('Failed %s: %s', uri, error) logging.debug('Debug info for %s: %s', uri, debug) - logging.info('Scanning %s', config['local']['music_path']) + logging.info('Scanning %s', config['local']['media_dir']) - scanner = Scanner(config['local']['music_path'], store, debug) + scanner = Scanner(config['local']['media_dir'], store, debug) try: scanner.start() except KeyboardInterrupt: @@ -68,7 +68,7 @@ def main(): logging.info('Done scanning; writing tag cache...') for row in mpd_translator.tracks_to_tag_cache_format( - tracks, config['mpd']['music_path']): + tracks, config['mpd']['media_dir']): if len(row) == 1: print ('%s' % row).encode('utf-8') else: diff --git a/tests/backends/local/events_test.py b/tests/backends/local/events_test.py index 83d77a2f..e09bf4b9 100644 --- a/tests/backends/local/events_test.py +++ b/tests/backends/local/events_test.py @@ -10,8 +10,8 @@ class LocalBackendEventsTest(events.BackendEventsTest, unittest.TestCase): backend_class = actor.LocalBackend config = { 'local': { - 'music_path': path_to_data_dir(''), - 'playlist_path': '', + 'media_dir': path_to_data_dir(''), + 'playlists_dir': '', 'tag_cache_file': path_to_data_dir('empty_tag_cache'), } } diff --git a/tests/backends/local/library_test.py b/tests/backends/local/library_test.py index e582c788..74635b3e 100644 --- a/tests/backends/local/library_test.py +++ b/tests/backends/local/library_test.py @@ -10,8 +10,8 @@ class LocalLibraryControllerTest(LibraryControllerTest, unittest.TestCase): backend_class = actor.LocalBackend config = { 'local': { - 'music_path': path_to_data_dir(''), - 'playlist_path': '', + 'media_dir': path_to_data_dir(''), + 'playlists_dir': '', 'tag_cache_file': path_to_data_dir('library_tag_cache'), } } diff --git a/tests/backends/local/playback_test.py b/tests/backends/local/playback_test.py index 4c304590..16592539 100644 --- a/tests/backends/local/playback_test.py +++ b/tests/backends/local/playback_test.py @@ -14,8 +14,8 @@ class LocalPlaybackControllerTest(PlaybackControllerTest, unittest.TestCase): backend_class = actor.LocalBackend config = { 'local': { - 'music_path': path_to_data_dir(''), - 'playlist_path': '', + 'media_dir': path_to_data_dir(''), + 'playlists_dir': '', 'tag_cache_file': path_to_data_dir('empty_tag_cache'), } } diff --git a/tests/backends/local/playlists_test.py b/tests/backends/local/playlists_test.py index 8528adf4..b35b504f 100644 --- a/tests/backends/local/playlists_test.py +++ b/tests/backends/local/playlists_test.py @@ -20,32 +20,32 @@ class LocalPlaylistsControllerTest( backend_class = actor.LocalBackend config = { 'local': { - 'music_path': path_to_data_dir(''), + 'media_dir': path_to_data_dir(''), 'tag_cache_file': path_to_data_dir('library_tag_cache'), } } def setUp(self): - self.config['local']['playlist_path'] = tempfile.mkdtemp() - self.playlist_path = self.config['local']['playlist_path'] + self.config['local']['playlists_dir'] = tempfile.mkdtemp() + self.playlists_dir = self.config['local']['playlists_dir'] super(LocalPlaylistsControllerTest, self).setUp() def tearDown(self): super(LocalPlaylistsControllerTest, self).tearDown() - if os.path.exists(self.playlist_path): - shutil.rmtree(self.playlist_path) + if os.path.exists(self.playlists_dir): + shutil.rmtree(self.playlists_dir) def test_created_playlist_is_persisted(self): - path = os.path.join(self.playlist_path, 'test.m3u') + path = os.path.join(self.playlists_dir, 'test.m3u') self.assertFalse(os.path.exists(path)) self.core.playlists.create('test') self.assertTrue(os.path.exists(path)) def test_create_slugifies_playlist_name(self): - path = os.path.join(self.playlist_path, 'test-foo-bar.m3u') + path = os.path.join(self.playlists_dir, 'test-foo-bar.m3u') self.assertFalse(os.path.exists(path)) playlist = self.core.playlists.create('test FOO baR') @@ -53,7 +53,7 @@ class LocalPlaylistsControllerTest( self.assertTrue(os.path.exists(path)) def test_create_slugifies_names_which_tries_to_change_directory(self): - path = os.path.join(self.playlist_path, 'test-foo-bar.m3u') + path = os.path.join(self.playlists_dir, 'test-foo-bar.m3u') self.assertFalse(os.path.exists(path)) playlist = self.core.playlists.create('../../test FOO baR') @@ -61,8 +61,8 @@ class LocalPlaylistsControllerTest( self.assertTrue(os.path.exists(path)) def test_saved_playlist_is_persisted(self): - path1 = os.path.join(self.playlist_path, 'test1.m3u') - path2 = os.path.join(self.playlist_path, 'test2-foo-bar.m3u') + path1 = os.path.join(self.playlists_dir, 'test1.m3u') + path2 = os.path.join(self.playlists_dir, 'test2-foo-bar.m3u') playlist = self.core.playlists.create('test1') @@ -77,7 +77,7 @@ class LocalPlaylistsControllerTest( self.assertTrue(os.path.exists(path2)) def test_deleted_playlist_is_removed(self): - path = os.path.join(self.playlist_path, 'test.m3u') + path = os.path.join(self.playlists_dir, 'test.m3u') self.assertFalse(os.path.exists(path)) playlist = self.core.playlists.create('test') @@ -100,7 +100,7 @@ class LocalPlaylistsControllerTest( self.assertEqual(track_path, contents.strip()) def test_playlists_are_loaded_at_startup(self): - playlist_path = os.path.join(self.playlist_path, 'test.m3u') + playlist_path = os.path.join(self.playlists_dir, 'test.m3u') track = Track(uri=path_to_uri(path_to_data_dir('uri2'))) playlist = self.core.playlists.create('test') diff --git a/tests/backends/local/tracklist_test.py b/tests/backends/local/tracklist_test.py index 3fc8a0be..2d8e87b6 100644 --- a/tests/backends/local/tracklist_test.py +++ b/tests/backends/local/tracklist_test.py @@ -12,8 +12,8 @@ class LocalTracklistControllerTest(TracklistControllerTest, unittest.TestCase): backend_class = actor.LocalBackend config = { 'local': { - 'music_path': path_to_data_dir(''), - 'playlist_path': '', + 'media_dir': path_to_data_dir(''), + 'playlists_dir': '', 'tag_cache_file': path_to_data_dir('empty_tag_cache'), } }