local: Rename 'music_path' to 'music_dir', 'playlist_path' to 'playlists_dir'

This commit is contained in:
Stein Magnus Jodal 2013-04-08 20:55:27 +02:00
parent 6e5cdb85b0
commit 3339b79c1e
9 changed files with 44 additions and 45 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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'),
}
}

View File

@ -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'),
}
}

View File

@ -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'),
}
}

View File

@ -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')

View File

@ -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'),
}
}