From 70fe571b055b9bc44267d06cd9a925197df81955 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 31 Oct 2010 20:58:58 +0100 Subject: [PATCH 1/6] Add special casing of _PATH settings --- mopidy/utils/settings.py | 3 +++ tests/utils/settings_test.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index ac75cb70..6286c8b9 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -51,6 +51,9 @@ class SettingsProxy(object): value = self.current[attr] if type(value) != bool and not value: raise SettingsError(u'Setting "%s" is empty.' % attr) + if attr.endswith('_PATH'): + value = os.path.expanduser(value) + value = os.path.abspath(value) return value def __setattr__(self, attr, value): diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index 0c06ae5c..a8b98647 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -1,3 +1,4 @@ +import os import unittest from mopidy import settings as default_settings_module @@ -65,3 +66,15 @@ class SettingsProxyTest(unittest.TestCase): def test_runtime_value_included_in_current(self): self.settings.TEST = 'test' self.assertEqual(self.settings.current['TEST'], 'test') + + def test_value_ending_in_path_is_expanded(self): + self.settings.TEST_PATH = '~/test' + acctual = self.settings.TEST_PATH + expected = os.path.expanduser('~/test') + self.assertEqual(acctual, expected) + + def test_value_ending_in_path_is_absolute(self): + self.settings.TEST_PATH = './test' + acctual = self.settings.TEST_PATH + expected = os.path.abspath('./test') + self.assertEqual(acctual, expected) From e8371129f74a696b004ac3bd7ad6ee893d7e455d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 31 Oct 2010 23:19:30 +0100 Subject: [PATCH 2/6] Add test to ensure that other values are not expanded --- tests/utils/settings_test.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index a8b98647..3b1d7439 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -73,8 +73,12 @@ class SettingsProxyTest(unittest.TestCase): expected = os.path.expanduser('~/test') self.assertEqual(acctual, expected) - def test_value_ending_in_path_is_absolute(self): - self.settings.TEST_PATH = './test' - acctual = self.settings.TEST_PATH - expected = os.path.abspath('./test') - self.assertEqual(acctual, expected) + def test_value_not_ending_in_path_is_not_expanded(self): + self.settings.TEST = '~/test' + acctual = self.settings.TEST + self.assertEqual(acctual, '~/test') + + def test_value_not_ending_in_path_is_not_absolute(self): + self.settings.TEST = './test' + acctual = self.settings.TEST + self.assertEqual(acctual, './test') From 3661800563ca59463f5b5e36b254ab7aaa207665 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 31 Oct 2010 23:33:04 +0100 Subject: [PATCH 3/6] Add _FILE handling --- mopidy/utils/settings.py | 2 +- tests/utils/settings_test.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 6286c8b9..3145d278 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -51,7 +51,7 @@ class SettingsProxy(object): value = self.current[attr] if type(value) != bool and not value: raise SettingsError(u'Setting "%s" is empty.' % attr) - if attr.endswith('_PATH'): + if attr.endswith('_PATH') or attr.endswith('_FILE'): value = os.path.expanduser(value) value = os.path.abspath(value) return value diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index 3b1d7439..cef0069d 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -73,12 +73,30 @@ class SettingsProxyTest(unittest.TestCase): expected = os.path.expanduser('~/test') self.assertEqual(acctual, expected) - def test_value_not_ending_in_path_is_not_expanded(self): + def test_value_ending_in_path_is_absolute(self): + self.settings.TEST_PATH = './test' + acctual = self.settings.TEST_PATH + expected = os.path.abspath('./test') + self.assertEqual(acctual, expected) + + def test_value_ending_in_file_is_expanded(self): + self.settings.TEST_FILE = '~/test' + acctual = self.settings.TEST_FILE + expected = os.path.expanduser('~/test') + self.assertEqual(acctual, expected) + + def test_value_ending_in_file_is_absolute(self): + self.settings.TEST_FILE = './test' + acctual = self.settings.TEST_FILE + expected = os.path.abspath('./test') + self.assertEqual(acctual, expected) + + def test_value_not_ending_in_path_or_file_is_not_expanded(self): self.settings.TEST = '~/test' acctual = self.settings.TEST self.assertEqual(acctual, '~/test') - def test_value_not_ending_in_path_is_not_absolute(self): + def test_value_not_ending_in_path_or_file_is_not_absolute(self): self.settings.TEST = './test' acctual = self.settings.TEST self.assertEqual(acctual, './test') From c513d0f6e7ea053628b240e185a572669b645b27 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 31 Oct 2010 23:44:45 +0100 Subject: [PATCH 4/6] Rename settings that have dirs or file to _PATH and _FILE --- bin/mopidy | 0 bin/mopidy-scan | 4 ++-- docs/settings.rst | 6 +++--- mopidy/backends/libspotify/__init__.py | 2 +- mopidy/backends/libspotify/session_manager.py | 4 ++-- mopidy/backends/local/__init__.py | 12 ++++++------ mopidy/frontends/mpd/translator.py | 4 ++-- mopidy/settings.py | 14 +++++++------- mopidy/utils/settings.py | 4 ++++ tests/backends/base/stored_playlists.py | 10 +++++----- tests/backends/local/library_test.py | 4 ++-- tests/backends/local/stored_playlists_test.py | 12 ++++++------ tests/frontends/mpd/serializer_test.py | 6 +++--- 13 files changed, 43 insertions(+), 39 deletions(-) mode change 100644 => 100755 bin/mopidy diff --git a/bin/mopidy b/bin/mopidy old mode 100644 new mode 100755 diff --git a/bin/mopidy-scan b/bin/mopidy-scan index 8534372c..1865f317 100755 --- a/bin/mopidy-scan +++ b/bin/mopidy-scan @@ -17,9 +17,9 @@ if __name__ == '__main__': def debug(uri, error): print >> sys.stderr, 'Failed %s: %s' % (uri, error) - print >> sys.stderr, 'Scanning %s' % settings.LOCAL_MUSIC_FOLDER + print >> sys.stderr, 'Scanning %s' % settings.LOCAL_MUSIC_PATH - scanner = Scanner(settings.LOCAL_MUSIC_FOLDER, store, debug) + scanner = Scanner(settings.LOCAL_MUSIC_PATH, store, debug) scanner.start() print >> sys.stderr, 'Done' diff --git a/docs/settings.rst b/docs/settings.rst index a7638b4e..41507a4a 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -47,12 +47,12 @@ Generating a tag cache Previously the local storage backend relied purely on ``tag_cache`` files generated by the original MPD server. To remedy this the command :command:`mopidy-scan` has been created. The program will scan your current -:attr:`mopidy.settings.LOCAL_MUSIC_FOLDER` and build a MPD compatible +:attr:`mopidy.settings.LOCAL_MUSIC_PATH` and build a MPD compatible ``tag_cache``. To make a ``tag_cache`` of your local music available for Mopidy: -#. Ensure that :attr:`mopidy.settings.LOCAL_MUSIC_FOLDER` points to where your +#. Ensure that :attr:`mopidy.settings.LOCAL_MUSIC_PATH` points to where your music is located. Check the current setting by running:: mopidy --list-settings @@ -64,7 +64,7 @@ To make a ``tag_cache`` of your local music available for Mopidy: mopidy-scan > tag_cache #. Move the ``tag_cache`` file to the location - :attr:`mopidy.settings.LOCAL_TAG_CACHE` is set to, or change the setting to + :attr:`mopidy.settings.LOCAL_TAG_CACHE_FILE` is set to, or change the setting to point to where your ``tag_cache`` file is. #. Start Mopidy, find the music library in a client, and play some local music! diff --git a/mopidy/backends/libspotify/__init__.py b/mopidy/backends/libspotify/__init__.py index 223d9968..75739d66 100644 --- a/mopidy/backends/libspotify/__init__.py +++ b/mopidy/backends/libspotify/__init__.py @@ -18,7 +18,7 @@ class LibspotifyBackend(BaseBackend): **Settings:** - - :attr:`mopidy.settings.SPOTIFY_LIB_CACHE` + - :attr:`mopidy.settings.SPOTIFY_CACHE_PATH` - :attr:`mopidy.settings.SPOTIFY_USERNAME` - :attr:`mopidy.settings.SPOTIFY_PASSWORD` diff --git a/mopidy/backends/libspotify/session_manager.py b/mopidy/backends/libspotify/session_manager.py index 45841350..3e11fc6f 100644 --- a/mopidy/backends/libspotify/session_manager.py +++ b/mopidy/backends/libspotify/session_manager.py @@ -15,8 +15,8 @@ logger = logging.getLogger('mopidy.backends.libspotify.session_manager') # LibspotifySessionManager: Too many ancestors (9/7) class LibspotifySessionManager(SpotifySessionManager, BaseThread): - cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) - settings_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE) + cache_location = os.path.expanduser(settings.SPOTIFY_CACHE_PATH) + settings_location = os.path.expanduser(settings.SPOTIFY_CACHE_PATH) appkey_file = os.path.join(os.path.dirname(__file__), 'spotify_appkey.key') user_agent = 'Mopidy %s' % get_version() diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index efcc3bbd..01dcf1df 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -23,9 +23,9 @@ class LocalBackend(BaseBackend): **Settings:** - - :attr:`mopidy.settings.LOCAL_MUSIC_FOLDER` - - :attr:`mopidy.settings.LOCAL_PLAYLIST_FOLDER` - - :attr:`mopidy.settings.LOCAL_TAG_CACHE` + - :attr:`mopidy.settings.LOCAL_MUSIC_PATH` + - :attr:`mopidy.settings.LOCAL_PLAYLIST_PATH` + - :attr:`mopidy.settings.LOCAL_TAG_CACHE_FILE` """ def __init__(self, *args, **kwargs): @@ -66,7 +66,7 @@ class LocalPlaybackController(BasePlaybackController): class LocalStoredPlaylistsController(BaseStoredPlaylistsController): def __init__(self, *args): super(LocalStoredPlaylistsController, self).__init__(*args) - self._folder = os.path.expanduser(settings.LOCAL_PLAYLIST_FOLDER) + self._folder = os.path.expanduser(settings.LOCAL_PLAYLIST_PATH) self.refresh() def lookup(self, uri): @@ -143,8 +143,8 @@ class LocalLibraryController(BaseLibraryController): self.refresh() def refresh(self, uri=None): - tag_cache = os.path.expanduser(settings.LOCAL_TAG_CACHE) - music_folder = os.path.expanduser(settings.LOCAL_MUSIC_FOLDER) + tag_cache = os.path.expanduser(settings.LOCAL_TAG_CACHE_FILE) + music_folder = os.path.expanduser(settings.LOCAL_MUSIC_PATH) tracks = parse_mpd_tag_cache(tag_cache, music_folder) diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index 2b1adf50..c7f5605a 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -129,7 +129,7 @@ def tracks_to_tag_cache_format(tracks): def _add_to_tag_cache(result, folders, files): for path, entry in folders.items(): name = os.path.split(path)[1] - music_folder = os.path.expanduser(settings.LOCAL_MUSIC_FOLDER) + music_folder = os.path.expanduser(settings.LOCAL_MUSIC_PATH) mtime = get_mtime(os.path.join(music_folder, path)) result.append(('directory', path)) result.append(('mtime', mtime)) @@ -150,7 +150,7 @@ def tracks_to_directory_tree(tracks): path = u'' current = directories - local_folder = os.path.expanduser(settings.LOCAL_MUSIC_FOLDER) + local_folder = os.path.expanduser(settings.LOCAL_MUSIC_PATH) track_path = uri_to_path(track.uri) track_path = re.sub('^' + re.escape(local_folder), '', track_path) track_dir = os.path.dirname(track_path) diff --git a/mopidy/settings.py b/mopidy/settings.py index c9d7b9fc..4f60ee99 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -77,8 +77,8 @@ LASTFM_PASSWORD = u'' #: #: Default:: #: -#: LOCAL_MUSIC_FOLDER = u'~/music' -LOCAL_MUSIC_FOLDER = u'~/music' +#: LOCAL_MUSIC_PATH = u'~/music' +LOCAL_MUSIC_PATH = u'~/music' #: Path to playlist folder with m3u files for local music. #: @@ -86,8 +86,8 @@ LOCAL_MUSIC_FOLDER = u'~/music' #: #: Default:: #: -#: LOCAL_PLAYLIST_FOLDER = u'~/.mopidy/playlists' -LOCAL_PLAYLIST_FOLDER = u'~/.mopidy/playlists' +#: LOCAL_PLAYLIST_PATH = u'~/.mopidy/playlists' +LOCAL_PLAYLIST_PATH = u'~/.mopidy/playlists' #: Path to tag cache for local music. #: @@ -95,8 +95,8 @@ LOCAL_PLAYLIST_FOLDER = u'~/.mopidy/playlists' #: #: Default:: #: -#: LOCAL_TAG_CACHE = u'~/.mopidy/tag_cache' -LOCAL_TAG_CACHE = u'~/.mopidy/tag_cache' +#: LOCAL_TAG_CACHE_FILE = u'~/.mopidy/tag_cache' +LOCAL_TAG_CACHE_FILE = u'~/.mopidy/tag_cache' #: Sound mixer to use. See :mod:`mopidy.mixers` for all available mixers. #: @@ -172,7 +172,7 @@ MPD_SERVER_PORT = 6600 #: Path to the libspotify cache. #: #: Used by :mod:`mopidy.backends.libspotify`. -SPOTIFY_LIB_CACHE = u'~/.mopidy/libspotify_cache' +SPOTIFY_CACHE_PATH = u'~/.mopidy/libspotify_cache' #: Your Spotify Premium username. #: diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 3145d278..2ec0f716 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -97,10 +97,14 @@ def validate_settings(defaults, settings): 'DUMP_LOG_FILENAME': 'DEBUG_LOG_FILENAME', 'DUMP_LOG_FORMAT': 'DEBUG_LOG_FORMAT', 'FRONTEND': 'FRONTENDS', + 'LOCAL_MUSIC_FOLDER': 'LOCAL_MUSIC_PATH', + 'LOCAL_PLAYLIST_FOLDER': 'LOCAL_PLAYLIST_PATH', + 'LOCAL_TAG_CACHE': 'LOCAL_TAG_CACHE_FILE', 'SERVER': None, 'SERVER_HOSTNAME': 'MPD_SERVER_HOSTNAME', 'SERVER_PORT': 'MPD_SERVER_PORT', 'SPOTIFY_LIB_APPKEY': None, + 'SPOTIFY_LIB_CACHE': 'SPOTIFY_CACHE_PATH', } for setting, value in settings.iteritems(): diff --git a/tests/backends/base/stored_playlists.py b/tests/backends/base/stored_playlists.py index ef5806ef..5bcd322c 100644 --- a/tests/backends/base/stored_playlists.py +++ b/tests/backends/base/stored_playlists.py @@ -10,9 +10,9 @@ from tests import SkipTest, data_folder class BaseStoredPlaylistsControllerTest(object): def setUp(self): - settings.LOCAL_PLAYLIST_FOLDER = tempfile.mkdtemp() - settings.LOCAL_TAG_CACHE = data_folder('library_tag_cache') - settings.LOCAL_MUSIC_FOLDER = data_folder('') + settings.LOCAL_PLAYLIST_PATH = tempfile.mkdtemp() + settings.LOCAL_TAG_CACHE_FILE = data_folder('library_tag_cache') + settings.LOCAL_MUSIC_PATH = data_folder('') self.backend = self.backend_class(mixer_class=DummyMixer) self.stored = self.backend.stored_playlists @@ -20,8 +20,8 @@ class BaseStoredPlaylistsControllerTest(object): def tearDown(self): self.backend.destroy() - if os.path.exists(settings.LOCAL_PLAYLIST_FOLDER): - shutil.rmtree(settings.LOCAL_PLAYLIST_FOLDER) + if os.path.exists(settings.LOCAL_PLAYLIST_PATH): + shutil.rmtree(settings.LOCAL_PLAYLIST_PATH) settings.runtime.clear() diff --git a/tests/backends/local/library_test.py b/tests/backends/local/library_test.py index c0605ef2..34465d09 100644 --- a/tests/backends/local/library_test.py +++ b/tests/backends/local/library_test.py @@ -17,8 +17,8 @@ class LocalLibraryControllerTest(BaseLibraryControllerTest, unittest.TestCase): backend_class = LocalBackend def setUp(self): - settings.LOCAL_TAG_CACHE = data_folder('library_tag_cache') - settings.LOCAL_MUSIC_FOLDER = data_folder('') + settings.LOCAL_TAG_CACHE_FILE = data_folder('library_tag_cache') + settings.LOCAL_MUSIC_PATH = data_folder('') super(LocalLibraryControllerTest, self).setUp() diff --git a/tests/backends/local/stored_playlists_test.py b/tests/backends/local/stored_playlists_test.py index bb03f997..4db9e1e2 100644 --- a/tests/backends/local/stored_playlists_test.py +++ b/tests/backends/local/stored_playlists_test.py @@ -25,13 +25,13 @@ class LocalStoredPlaylistsControllerTest(BaseStoredPlaylistsControllerTest, backend_class = LocalBackend def test_created_playlist_is_persisted(self): - path = os.path.join(settings.LOCAL_PLAYLIST_FOLDER, 'test.m3u') + path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') self.assert_(not os.path.exists(path)) self.stored.create('test') self.assert_(os.path.exists(path)) def test_saved_playlist_is_persisted(self): - path = os.path.join(settings.LOCAL_PLAYLIST_FOLDER, 'test2.m3u') + path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test2.m3u') self.assert_(not os.path.exists(path)) self.stored.save(Playlist(name='test2')) self.assert_(os.path.exists(path)) @@ -39,13 +39,13 @@ class LocalStoredPlaylistsControllerTest(BaseStoredPlaylistsControllerTest, def test_deleted_playlist_get_removed(self): playlist = self.stored.create('test') self.stored.delete(playlist) - path = os.path.join(settings.LOCAL_PLAYLIST_FOLDER, 'test.m3u') + path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') self.assert_(not os.path.exists(path)) def test_renamed_playlist_gets_moved(self): playlist = self.stored.create('test') - file1 = os.path.join(settings.LOCAL_PLAYLIST_FOLDER, 'test.m3u') - file2 = os.path.join(settings.LOCAL_PLAYLIST_FOLDER, 'test2.m3u') + file1 = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') + file2 = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test2.m3u') self.assert_(not os.path.exists(file2)) self.stored.rename(playlist, 'test2') self.assert_(not os.path.exists(file1)) @@ -55,7 +55,7 @@ class LocalStoredPlaylistsControllerTest(BaseStoredPlaylistsControllerTest, track = Track(uri=generate_song(1)) uri = track.uri[len('file://'):] playlist = Playlist(tracks=[track], name='test') - path = os.path.join(settings.LOCAL_PLAYLIST_FOLDER, 'test.m3u') + path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') self.stored.save(playlist) diff --git a/tests/frontends/mpd/serializer_test.py b/tests/frontends/mpd/serializer_test.py index 8e8a5d21..db0dabf4 100644 --- a/tests/frontends/mpd/serializer_test.py +++ b/tests/frontends/mpd/serializer_test.py @@ -11,7 +11,7 @@ from tests import data_folder, SkipTest class TrackMpdFormatTest(unittest.TestCase): def setUp(self): - settings.LOCAL_MUSIC_FOLDER = '/dir/subdir' + settings.LOCAL_MUSIC_PATH = '/dir/subdir' mtime.set_fake_time(1234567) def tearDown(self): @@ -104,7 +104,7 @@ class PlaylistMpdFormatTest(unittest.TestCase): class TracksToTagCacheFormatTest(unittest.TestCase): def setUp(self): - settings.LOCAL_MUSIC_FOLDER = '/dir/subdir' + settings.LOCAL_MUSIC_PATH = '/dir/subdir' mtime.set_fake_time(1234567) def tearDown(self): @@ -279,7 +279,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase): class TracksToDirectoryTreeTest(unittest.TestCase): def setUp(self): - settings.LOCAL_MUSIC_FOLDER = '/root/' + settings.LOCAL_MUSIC_PATH = '/root/' def tearDown(self): settings.runtime.clear() From fe309d374e0934b481a3b3d87886692f362621fb Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 31 Oct 2010 23:51:10 +0100 Subject: [PATCH 5/6] Get rid of all kinds of abspath and expandpath usage that is no longer needed --- mopidy/backends/libspotify/session_manager.py | 4 ++-- mopidy/backends/local/__init__.py | 6 +++--- mopidy/frontends/mpd/translator.py | 4 ++-- mopidy/scanner.py | 1 - mopidy/utils/path.py | 12 +++--------- tests/utils/path_test.py | 6 ------ 6 files changed, 10 insertions(+), 23 deletions(-) diff --git a/mopidy/backends/libspotify/session_manager.py b/mopidy/backends/libspotify/session_manager.py index 3e11fc6f..5831b713 100644 --- a/mopidy/backends/libspotify/session_manager.py +++ b/mopidy/backends/libspotify/session_manager.py @@ -15,8 +15,8 @@ logger = logging.getLogger('mopidy.backends.libspotify.session_manager') # LibspotifySessionManager: Too many ancestors (9/7) class LibspotifySessionManager(SpotifySessionManager, BaseThread): - cache_location = os.path.expanduser(settings.SPOTIFY_CACHE_PATH) - settings_location = os.path.expanduser(settings.SPOTIFY_CACHE_PATH) + cache_location = settings.SPOTIFY_CACHE_PATH + settings_location = settings.SPOTIFY_CACHE_PATH appkey_file = os.path.join(os.path.dirname(__file__), 'spotify_appkey.key') user_agent = 'Mopidy %s' % get_version() diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 01dcf1df..21eea945 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -66,7 +66,7 @@ class LocalPlaybackController(BasePlaybackController): class LocalStoredPlaylistsController(BaseStoredPlaylistsController): def __init__(self, *args): super(LocalStoredPlaylistsController, self).__init__(*args) - self._folder = os.path.expanduser(settings.LOCAL_PLAYLIST_PATH) + self._folder = settings.LOCAL_PLAYLIST_PATH self.refresh() def lookup(self, uri): @@ -143,8 +143,8 @@ class LocalLibraryController(BaseLibraryController): self.refresh() def refresh(self, uri=None): - tag_cache = os.path.expanduser(settings.LOCAL_TAG_CACHE_FILE) - music_folder = os.path.expanduser(settings.LOCAL_MUSIC_PATH) + tag_cache = settings.LOCAL_TAG_CACHE_FILE + music_folder = settings.LOCAL_MUSIC_PATH tracks = parse_mpd_tag_cache(tag_cache, music_folder) diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index c7f5605a..fc1f031b 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -129,7 +129,7 @@ def tracks_to_tag_cache_format(tracks): def _add_to_tag_cache(result, folders, files): for path, entry in folders.items(): name = os.path.split(path)[1] - music_folder = os.path.expanduser(settings.LOCAL_MUSIC_PATH) + music_folder = settings.LOCAL_MUSIC_PATH mtime = get_mtime(os.path.join(music_folder, path)) result.append(('directory', path)) result.append(('mtime', mtime)) @@ -150,7 +150,7 @@ def tracks_to_directory_tree(tracks): path = u'' current = directories - local_folder = os.path.expanduser(settings.LOCAL_MUSIC_PATH) + local_folder = settings.LOCAL_MUSIC_PATH track_path = uri_to_path(track.uri) track_path = re.sub('^' + re.escape(local_folder), '', track_path) track_dir = os.path.dirname(track_path) diff --git a/mopidy/scanner.py b/mopidy/scanner.py index 436598bd..4ccccbdb 100644 --- a/mopidy/scanner.py +++ b/mopidy/scanner.py @@ -5,7 +5,6 @@ import pygst pygst.require('0.10') import gst -from os.path import abspath import datetime import sys import threading diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index b3669e38..5476e1fd 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -7,14 +7,12 @@ import urllib logger = logging.getLogger('mopidy.utils.path') def get_or_create_folder(folder): - folder = os.path.expanduser(folder) if not os.path.isdir(folder): logger.info(u'Creating dir %s', folder) os.mkdir(folder, 0755) return folder def get_or_create_file(filename): - filename = os.path.expanduser(filename) if not os.path.isfile(filename): logger.info(u'Creating file %s', filename) open(filename, 'w') @@ -22,7 +20,6 @@ def get_or_create_file(filename): def path_to_uri(*paths): path = os.path.join(*paths) - #path = os.path.expanduser(path) # FIXME Waiting for test case? path = path.encode('utf-8') if sys.platform == 'win32': return 'file:' + urllib.pathname2url(path) @@ -46,16 +43,13 @@ def split_path(path): return parts def find_files(path): - path = os.path.expanduser(path) if os.path.isfile(path): - filename = os.path.abspath(path) - if not isinstance(filename, unicode): - filename = filename.decode('utf-8') - yield filename + if not isinstance(path, unicode): + path = path.decode('utf-8') + yield path else: for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: - dirpath = os.path.abspath(dirpath) filename = os.path.join(dirpath, filename) if not isinstance(filename, unicode): filename = filename.decode('utf-8') diff --git a/tests/utils/path_test.py b/tests/utils/path_test.py index 758a09ab..4366305c 100644 --- a/tests/utils/path_test.py +++ b/tests/utils/path_test.py @@ -34,9 +34,6 @@ class GetOrCreateFolderTest(unittest.TestCase): self.assert_(os.path.isdir(self.parent)) self.assertEqual(created, self.parent) - def test_that_userfolder_is_expanded(self): - raise SkipTest # Not sure how to safely test this - class PathToFileURITest(unittest.TestCase): def test_simple_path(self): @@ -139,9 +136,6 @@ class FindFilesTest(unittest.TestCase): self.assert_(is_unicode(name), '%s is not unicode object' % repr(name)) - def test_expanduser(self): - raise SkipTest - class MtimeTest(unittest.TestCase): def tearDown(self): From 71ee3a8ef74db145af731a0b2fd46b9c029e7bc9 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Mon, 1 Nov 2010 00:07:59 +0100 Subject: [PATCH 6/6] Don't remove expanduser from get_or_create_file and get_or_create_folder --- mopidy/utils/path.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index 5476e1fd..f25d754a 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -7,12 +7,14 @@ import urllib logger = logging.getLogger('mopidy.utils.path') def get_or_create_folder(folder): + folder = os.path.expanduser(folder) if not os.path.isdir(folder): logger.info(u'Creating dir %s', folder) os.mkdir(folder, 0755) return folder def get_or_create_file(filename): + filename = os.path.expanduser(filename) if not os.path.isfile(filename): logger.info(u'Creating file %s', filename) open(filename, 'w')