From 085b44e52fc7620403212d0a189d70ff03b4bf9a Mon Sep 17 00:00:00 2001 From: Thomas Adacmik Date: Sat, 27 Apr 2013 02:21:27 +0200 Subject: [PATCH] path: Update with respect to review comments in #427 --- mopidy/backends/local/actor.py | 11 +++++++---- mopidy/backends/local/translator.py | 2 ++ mopidy/frontends/mpd/translator.py | 2 +- mopidy/scanner.py | 2 +- tests/config/types_test.py | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mopidy/backends/local/actor.py b/mopidy/backends/local/actor.py index 75cc485f..8f53af4d 100644 --- a/mopidy/backends/local/actor.py +++ b/mopidy/backends/local/actor.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import logging -import os.path +import os import pykka @@ -33,9 +33,12 @@ class LocalBackend(pykka.ThreadingActor, base.Backend): logger.warning('Local media dir %s does not exist.' % self.config['local']['media_dir']) - if not os.path.isdir(self.config['local']['playlists_dir']): - logger.warning('Local playlists dir %s does not exist.' % - self.config['local']['playlists_dir']) + try: + path.get_or_create_dir(self.config['local']['playlists_dir']) + except EnvironmentError as error: + logger.warning( + 'Could not create local playlists dir: %s', + encoding.locale_decode(error)) try: path.get_or_create_file(self.config['local']['tag_cache_file']) diff --git a/mopidy/backends/local/translator.py b/mopidy/backends/local/translator.py index 683ad6b4..c53011f6 100644 --- a/mopidy/backends/local/translator.py +++ b/mopidy/backends/local/translator.py @@ -31,6 +31,7 @@ def parse_m3u(file_path, media_dir): - This function does not bother with Extended M3U directives. """ + # TODO: uris as bytes uris = [] try: with open(file_path) as m3u: @@ -71,6 +72,7 @@ def parse_mpd_tag_cache(tag_cache, music_dir=''): current = {} state = None + # TODO: uris as bytes for line in contents.split(b'\n'): if line == b'songList begin': state = 'songs' diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index 7cf5b0c6..e164883d 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -236,7 +236,7 @@ def tracks_to_tag_cache_format(tracks, media_dir): _add_to_tag_cache(result, dirs, files, media_dir) return result - +# TODO: bytes only def _add_to_tag_cache(result, dirs, files, media_dir): base_path = media_dir.encode('utf-8') diff --git a/mopidy/scanner.py b/mopidy/scanner.py index d86568b3..fc80f95b 100644 --- a/mopidy/scanner.py +++ b/mopidy/scanner.py @@ -51,7 +51,7 @@ def main(): log.setup_log_levels(config) if not config['local']['media_dir']: - logging.warning('local/media_dir is not set.') + logging.warning('Config value local/media_dir is not set.') return # TODO: missing error checking and other default setup code. diff --git a/tests/config/types_test.py b/tests/config/types_test.py index ea07d5f5..65732f56 100644 --- a/tests/config/types_test.py +++ b/tests/config/types_test.py @@ -326,7 +326,7 @@ class ExpandedPathTest(unittest.TestCase): def test_is_bytes(self): self.assertIsInstance(types.ExpandedPath(b'/tmp', b'foo'), bytes) - def test_defaults_to_expanded(self,): + def test_defaults_to_expanded(self): original = b'~' expanded = b'expanded_path' self.assertEqual(expanded, types.ExpandedPath(original, expanded))