Merge pull request #403 from jodal/feature/rename-path-to-dir

Use "dir" instead of "folder" or "path"
This commit is contained in:
Thomas Adamcik 2013-04-08 15:12:13 -07:00
commit 423b7a326a
19 changed files with 144 additions and 150 deletions

View File

@ -309,9 +309,9 @@ def validate_config(raw_config, schemas, extensions=None):
def create_file_structures():
path.get_or_create_folder(path.DATA_PATH)
path.get_or_create_folder(path.CONFIG_PATH)
path.get_or_create_file(path.CONFIG_FILE)
path.get_or_create_dir('$XDG_DATA_DIR/mopidy')
path.get_or_create_dir('$XDG_CONFIG_DIR/mopidy')
path.get_or_create_file('$XDG_CONFIG_DIR/mopidy/mopidy.conf')
def setup_audio(config):

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

@ -10,7 +10,7 @@ from mopidy.utils.path import path_to_uri
logger = logging.getLogger('mopidy.backends.local')
def parse_m3u(file_path, music_folder):
def parse_m3u(file_path, media_dir):
r"""
Convert M3U file list of uris
@ -49,7 +49,7 @@ def parse_m3u(file_path, music_folder):
if line.startswith('file://'):
uris.append(line)
else:
path = path_to_uri(music_folder, line)
path = path_to_uri(media_dir, line)
uris.append(path)
return uris

View File

@ -25,7 +25,7 @@ bitrate = 160
timeout = 10
# Path to the Spotify data cache. Cannot be shared with other Spotify apps
cache_path = $XDG_CACHE_DIR/mopidy/spotify
cache_dir = $XDG_CACHE_DIR/mopidy/spotify
"""
__doc__ = """A backend for playing music from Spotify
@ -75,7 +75,7 @@ class Extension(ext.Extension):
schema['password'] = config.String(secret=True)
schema['bitrate'] = config.Integer(choices=(96, 160, 320))
schema['timeout'] = config.Integer(minimum=0)
schema['cache_path'] = config.Path()
schema['cache_dir'] = config.Path()
return schema
def validate_environment(self):

View File

@ -30,8 +30,8 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager):
def __init__(self, config, audio, backend_ref):
self.cache_location = config['spotify']['cache_path']
self.settings_location = config['spotify']['cache_path']
self.cache_location = config['spotify']['cache_dir']
self.settings_location = config['spotify']['cache_dir']
PyspotifySessionManager.__init__(
self, config['spotify']['username'], config['spotify']['password'],

View File

@ -215,14 +215,14 @@ def query_from_mpd_search_format(mpd_query):
return query
def tracks_to_tag_cache_format(tracks, music_path):
def tracks_to_tag_cache_format(tracks, media_dir):
"""
Format list of tracks for output to MPD tag cache
:param tracks: the tracks
:type tracks: list of :class:`mopidy.models.Track`
:param music_path: the path to the music dir
:type music_path: string
:param media_dir: the path to the music dir
:type media_dir: string
:rtype: list of lists of two-tuples
"""
result = [
@ -232,15 +232,15 @@ def tracks_to_tag_cache_format(tracks, music_path):
('info_end',)
]
tracks.sort(key=lambda t: t.uri)
folders, files = tracks_to_directory_tree(tracks, music_path)
_add_to_tag_cache(result, folders, files, music_path)
dirs, files = tracks_to_directory_tree(tracks, media_dir)
_add_to_tag_cache(result, dirs, files, media_dir)
return result
def _add_to_tag_cache(result, folders, files, music_path):
base_path = music_path.encode('utf-8')
def _add_to_tag_cache(result, dirs, files, media_dir):
base_path = media_dir.encode('utf-8')
for path, (entry_folders, entry_files) in folders.items():
for path, (entry_dirs, entry_files) in dirs.items():
try:
text_path = path.decode('utf-8')
except UnicodeDecodeError:
@ -249,7 +249,7 @@ def _add_to_tag_cache(result, folders, files, music_path):
result.append(('directory', text_path))
result.append(('mtime', get_mtime(os.path.join(base_path, path))))
result.append(('begin', name))
_add_to_tag_cache(result, entry_folders, entry_files, music_path)
_add_to_tag_cache(result, entry_dirs, entry_files, media_dir)
result.append(('end', name))
result.append(('songList begin',))
@ -275,7 +275,7 @@ def _add_to_tag_cache(result, folders, files, music_path):
result.append(('songList end',))
def tracks_to_directory_tree(tracks, music_path):
def tracks_to_directory_tree(tracks, media_dir):
directories = ({}, [])
for track in tracks:
@ -284,7 +284,7 @@ def tracks_to_directory_tree(tracks, music_path):
absolute_track_dir_path = os.path.dirname(uri_to_path(track.uri))
relative_track_dir_path = re.sub(
'^' + re.escape(music_path), b'', absolute_track_dir_path)
'^' + re.escape(media_dir), b'', absolute_track_dir_path)
for part in split_path(relative_track_dir_path):
path = os.path.join(path, part)

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:
@ -142,9 +142,9 @@ def translator(data):
class Scanner(object):
def __init__(self, folder, data_callback, error_callback=None):
def __init__(self, base_dir, data_callback, error_callback=None):
self.data = {}
self.files = path.find_files(folder)
self.files = path.find_files(base_dir)
self.data_callback = data_callback
self.error_callback = error_callback
self.loop = gobject.MainLoop()

View File

@ -25,27 +25,22 @@ XDG_DIRS = {
'XDG_DATA_DIR': XDG_DATA_DIR,
'XDG_MUSIC_DIR': XDG_MUSIC_DIR,
}
DATA_PATH = os.path.join(unicode(XDG_DATA_DIR), 'mopidy')
CONFIG_PATH = os.path.join(unicode(XDG_CONFIG_DIR), 'mopidy')
CONFIG_FILE = os.path.join(unicode(CONFIG_PATH), 'mopidy.conf')
SETTINGS_PATH = os.path.join(unicode(XDG_CONFIG_DIR), 'mopidy')
SETTINGS_FILE = os.path.join(unicode(SETTINGS_PATH), 'settings.py')
def get_or_create_folder(folder):
folder = os.path.expanduser(folder)
if os.path.isfile(folder):
def get_or_create_dir(dir_path):
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.' % folder)
elif not os.path.isdir(folder):
logger.info('Creating dir %s', folder)
os.makedirs(folder, 0755)
return folder
'"%s", already exists.' % dir_path)
elif not os.path.isdir(dir_path):
logger.info('Creating dir %s', dir_path)
os.makedirs(dir_path, 0755)
return dir_path
def get_or_create_file(filename):
filename = os.path.expanduser(filename)
filename = expand_path(filename)
if not os.path.isfile(filename):
logger.info('Creating file %s', filename)
open(filename, 'w')
@ -126,7 +121,7 @@ def find_files(path):
for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
for dirname in dirnames:
if dirname.startswith(b'.'):
# Skip hidden folders by modifying dirnames inplace
# Skip hidden dirs by modifying dirnames inplace
dirnames.remove(dirname)
for filename in filenames:

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')
@ -123,5 +123,5 @@ class LocalPlaylistsControllerTest(
pass
@unittest.SkipTest
def test_playlist_folder_is_createad(self):
def test_playlist_dir_is_created(self):
pass

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

View File

@ -35,7 +35,7 @@ class M3UToUriTest(unittest.TestCase):
uris = parse_m3u(path_to_data_dir('comment.m3u'), data_dir)
self.assertEqual([song1_uri], uris)
def test_file_is_relative_to_correct_folder(self):
def test_file_is_relative_to_correct_dir(self):
with tempfile.NamedTemporaryFile(delete=False) as tmp:
tmp.write('song1.mp3')
try:

View File

@ -23,7 +23,7 @@ class TrackMpdFormatTest(unittest.TestCase):
)
def setUp(self):
self.music_path = '/dir/subdir'
self.media_dir = '/dir/subdir'
mtime.set_fake_time(1234567)
def tearDown(self):
@ -135,14 +135,14 @@ class QueryFromMpdListFormatTest(unittest.TestCase):
class TracksToTagCacheFormatTest(unittest.TestCase):
def setUp(self):
self.music_path = '/dir/subdir'
self.media_dir = '/dir/subdir'
mtime.set_fake_time(1234567)
def tearDown(self):
mtime.undo_fake()
def translate(self, track):
base_path = self.music_path.encode('utf-8')
base_path = self.media_dir.encode('utf-8')
result = dict(translator.track_to_mpd_format(track))
result['file'] = uri_to_path(result['file'])[len(base_path) + 1:]
result['key'] = os.path.basename(result['file'])
@ -174,11 +174,11 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
self.fail("Couldn't find end %s in result" % directory)
def test_empty_tag_cache_has_header(self):
result = translator.tracks_to_tag_cache_format([], self.music_path)
result = translator.tracks_to_tag_cache_format([], self.media_dir)
result = self.consume_headers(result)
def test_empty_tag_cache_has_song_list(self):
result = translator.tracks_to_tag_cache_format([], self.music_path)
result = translator.tracks_to_tag_cache_format([], self.media_dir)
result = self.consume_headers(result)
song_list, result = self.consume_song_list(result)
@ -187,12 +187,12 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
def test_tag_cache_has_header(self):
track = Track(uri='file:///dir/subdir/song.mp3')
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
def test_tag_cache_has_song_list(self):
track = Track(uri='file:///dir/subdir/song.mp3')
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
song_list, result = self.consume_song_list(result)
@ -202,7 +202,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
def test_tag_cache_has_formated_track(self):
track = Track(uri='file:///dir/subdir/song.mp3')
formated = self.translate(track)
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
song_list, result = self.consume_song_list(result)
@ -213,7 +213,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
def test_tag_cache_has_formated_track_with_key_and_mtime(self):
track = Track(uri='file:///dir/subdir/song.mp3')
formated = self.translate(track)
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
song_list, result = self.consume_song_list(result)
@ -221,50 +221,50 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
self.assertEqual(formated, song_list)
self.assertEqual(len(result), 0)
def test_tag_cache_suports_directories(self):
def test_tag_cache_supports_directories(self):
track = Track(uri='file:///dir/subdir/folder/song.mp3')
formated = self.translate(track)
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
folder, result = self.consume_directory(result)
dir_data, result = self.consume_directory(result)
song_list, result = self.consume_song_list(result)
self.assertEqual(len(song_list), 0)
self.assertEqual(len(result), 0)
song_list, result = self.consume_song_list(folder)
song_list, result = self.consume_song_list(dir_data)
self.assertEqual(len(result), 0)
self.assertEqual(formated, song_list)
def test_tag_cache_diretory_header_is_right(self):
track = Track(uri='file:///dir/subdir/folder/sub/song.mp3')
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
folder, result = self.consume_directory(result)
dir_data, result = self.consume_directory(result)
self.assertEqual(('directory', 'folder/sub'), folder[0])
self.assertEqual(('mtime', mtime('.')), folder[1])
self.assertEqual(('begin', 'sub'), folder[2])
self.assertEqual(('directory', 'folder/sub'), dir_data[0])
self.assertEqual(('mtime', mtime('.')), dir_data[1])
self.assertEqual(('begin', 'sub'), dir_data[2])
def test_tag_cache_suports_sub_directories(self):
track = Track(uri='file:///dir/subdir/folder/sub/song.mp3')
formated = self.translate(track)
result = translator.tracks_to_tag_cache_format([track], self.music_path)
result = translator.tracks_to_tag_cache_format([track], self.media_dir)
result = self.consume_headers(result)
folder, result = self.consume_directory(result)
dir_data, result = self.consume_directory(result)
song_list, result = self.consume_song_list(result)
self.assertEqual(len(song_list), 0)
self.assertEqual(len(result), 0)
folder, result = self.consume_directory(folder)
dir_data, result = self.consume_directory(dir_data)
song_list, result = self.consume_song_list(result)
self.assertEqual(len(result), 0)
self.assertEqual(len(song_list), 0)
song_list, result = self.consume_song_list(folder)
song_list, result = self.consume_song_list(dir_data)
self.assertEqual(len(result), 0)
self.assertEqual(formated, song_list)
@ -278,7 +278,7 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
formated.extend(self.translate(tracks[0]))
formated.extend(self.translate(tracks[1]))
result = translator.tracks_to_tag_cache_format(tracks, self.music_path)
result = translator.tracks_to_tag_cache_format(tracks, self.media_dir)
result = self.consume_headers(result)
song_list, result = self.consume_song_list(result)
@ -296,11 +296,11 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
formated.append(self.translate(tracks[0]))
formated.append(self.translate(tracks[1]))
result = translator.tracks_to_tag_cache_format(tracks, self.music_path)
result = translator.tracks_to_tag_cache_format(tracks, self.media_dir)
result = self.consume_headers(result)
folder, result = self.consume_directory(result)
song_list, song_result = self.consume_song_list(folder)
dir_data, result = self.consume_directory(result)
song_list, song_result = self.consume_song_list(dir_data)
self.assertEqual(formated[1], song_list)
self.assertEqual(len(song_result), 0)
@ -312,10 +312,10 @@ class TracksToTagCacheFormatTest(unittest.TestCase):
class TracksToDirectoryTreeTest(unittest.TestCase):
def setUp(self):
self.music_path = '/root'
self.media_dir = '/root'
def test_no_tracks_gives_emtpy_tree(self):
tree = translator.tracks_to_directory_tree([], self.music_path)
tree = translator.tracks_to_directory_tree([], self.media_dir)
self.assertEqual(tree, ({}, []))
def test_top_level_files(self):
@ -324,18 +324,18 @@ class TracksToDirectoryTreeTest(unittest.TestCase):
Track(uri='file:///root/file2.mp3'),
Track(uri='file:///root/file3.mp3'),
]
tree = translator.tracks_to_directory_tree(tracks, self.music_path)
tree = translator.tracks_to_directory_tree(tracks, self.media_dir)
self.assertEqual(tree, ({}, tracks))
def test_single_file_in_subdir(self):
tracks = [Track(uri='file:///root/dir/file1.mp3')]
tree = translator.tracks_to_directory_tree(tracks, self.music_path)
tree = translator.tracks_to_directory_tree(tracks, self.media_dir)
expected = ({'dir': ({}, tracks)}, [])
self.assertEqual(tree, expected)
def test_single_file_in_sub_subdir(self):
tracks = [Track(uri='file:///root/dir1/dir2/file1.mp3')]
tree = translator.tracks_to_directory_tree(tracks, self.music_path)
tree = translator.tracks_to_directory_tree(tracks, self.media_dir)
expected = ({'dir1': ({'dir1/dir2': ({}, tracks)}, [])}, [])
self.assertEqual(tree, expected)
@ -347,7 +347,7 @@ class TracksToDirectoryTreeTest(unittest.TestCase):
Track(uri='file:///root/dir2/file4.mp3'),
Track(uri='file:///root/dir2/sub/file5.mp3'),
]
tree = translator.tracks_to_directory_tree(tracks, self.music_path)
tree = translator.tracks_to_directory_tree(tracks, self.media_dir)
expected = (
{
'dir1': ({}, [tracks[1], tracks[2]]),

View File

@ -196,7 +196,7 @@ class ScannerTest(unittest.TestCase):
self.check('scanner/simple/song1.mp3', 'title', 'trackname')
self.check('scanner/simple/song1.ogg', 'title', 'trackname')
def test_nonexistant_folder_does_not_fail(self):
def test_nonexistant_dir_does_not_fail(self):
self.scan('scanner/does-not-exist')
self.assert_(not self.errors)

View File

@ -13,7 +13,7 @@ from mopidy.utils import path
from tests import unittest, path_to_data_dir
class GetOrCreateFolderTest(unittest.TestCase):
class GetOrCreateDirTest(unittest.TestCase):
def setUp(self):
self.parent = tempfile.mkdtemp()
@ -21,40 +21,40 @@ class GetOrCreateFolderTest(unittest.TestCase):
if os.path.isdir(self.parent):
shutil.rmtree(self.parent)
def test_creating_folder(self):
folder = os.path.join(self.parent, 'test')
self.assert_(not os.path.exists(folder))
self.assert_(not os.path.isdir(folder))
created = path.get_or_create_folder(folder)
self.assert_(os.path.exists(folder))
self.assert_(os.path.isdir(folder))
self.assertEqual(created, folder)
def test_creating_dir(self):
dir_path = os.path.join(self.parent, 'test')
self.assert_(not os.path.exists(dir_path))
self.assert_(not os.path.isdir(dir_path))
created = path.get_or_create_dir(dir_path)
self.assert_(os.path.exists(dir_path))
self.assert_(os.path.isdir(dir_path))
self.assertEqual(created, dir_path)
def test_creating_nested_folders(self):
level2_folder = os.path.join(self.parent, 'test')
level3_folder = os.path.join(self.parent, 'test', 'test')
self.assert_(not os.path.exists(level2_folder))
self.assert_(not os.path.isdir(level2_folder))
self.assert_(not os.path.exists(level3_folder))
self.assert_(not os.path.isdir(level3_folder))
created = path.get_or_create_folder(level3_folder)
self.assert_(os.path.exists(level2_folder))
self.assert_(os.path.isdir(level2_folder))
self.assert_(os.path.exists(level3_folder))
self.assert_(os.path.isdir(level3_folder))
self.assertEqual(created, level3_folder)
def test_creating_nested_dirs(self):
level2_dir = os.path.join(self.parent, 'test')
level3_dir = os.path.join(self.parent, 'test', 'test')
self.assert_(not os.path.exists(level2_dir))
self.assert_(not os.path.isdir(level2_dir))
self.assert_(not os.path.exists(level3_dir))
self.assert_(not os.path.isdir(level3_dir))
created = path.get_or_create_dir(level3_dir)
self.assert_(os.path.exists(level2_dir))
self.assert_(os.path.isdir(level2_dir))
self.assert_(os.path.exists(level3_dir))
self.assert_(os.path.isdir(level3_dir))
self.assertEqual(created, level3_dir)
def test_creating_existing_folder(self):
created = path.get_or_create_folder(self.parent)
def test_creating_existing_dir(self):
created = path.get_or_create_dir(self.parent)
self.assert_(os.path.exists(self.parent))
self.assert_(os.path.isdir(self.parent))
self.assertEqual(created, self.parent)
def test_create_folder_with_name_of_existing_file_throws_oserror(self):
def test_create_dir_with_name_of_existing_file_throws_oserror(self):
conflicting_file = os.path.join(self.parent, 'test')
open(conflicting_file, 'w').close()
folder = os.path.join(self.parent, 'test')
self.assertRaises(OSError, path.get_or_create_folder, folder)
dir_path = os.path.join(self.parent, 'test')
self.assertRaises(OSError, path.get_or_create_dir, dir_path)
class PathToFileURITest(unittest.TestCase):
@ -66,7 +66,7 @@ class PathToFileURITest(unittest.TestCase):
result = path.path_to_uri('/etc/fstab')
self.assertEqual(result, 'file:///etc/fstab')
def test_folder_and_path(self):
def test_dir_and_path(self):
if sys.platform == 'win32':
result = path.path_to_uri('C:/WINDOWS/', 'clock.avi')
self.assertEqual(result, 'file:///C://WINDOWS/clock.avi')
@ -145,10 +145,10 @@ class SplitPathTest(unittest.TestCase):
def test_empty_path(self):
self.assertEqual([], path.split_path(''))
def test_single_folder(self):
def test_single_dir(self):
self.assertEqual(['foo'], path.split_path('foo'))
def test_folders(self):
def test_dirs(self):
self.assertEqual(['foo', 'bar', 'baz'], path.split_path('foo/bar/baz'))
def test_initial_slash_is_ignored(self):
@ -190,10 +190,10 @@ class FindFilesTest(unittest.TestCase):
def find(self, value):
return list(path.find_files(path_to_data_dir(value)))
def test_basic_folder(self):
def test_basic_dir(self):
self.assert_(self.find(''))
def test_nonexistant_folder(self):
def test_nonexistant_dir(self):
self.assertEqual(self.find('does-not-exist'), [])
def test_file(self):
@ -207,7 +207,7 @@ class FindFilesTest(unittest.TestCase):
self.assert_(
is_bytes(name), '%s is not bytes object' % repr(name))
def test_ignores_hidden_folders(self):
def test_ignores_hidden_dirs(self):
self.assertEqual(self.find('.hidden'), [])
def test_ignores_hidden_files(self):