local: Review comment fixes
This commit is contained in:
parent
118095e522
commit
3bbcb4d121
@ -52,10 +52,11 @@ class ScanCommand(commands.Command):
|
||||
tracks = local_updater.load()
|
||||
logger.info('Checking %d tracks from library.', len(tracks))
|
||||
for track in tracks:
|
||||
track_path = translator.local_to_path(track.uri, media_dir)
|
||||
uri_path_mapping[track.uri] = track_path
|
||||
uri_path_mapping[track.uri] = translator.local_track_uri_to_path(
|
||||
track.uri, media_dir)
|
||||
try:
|
||||
if int(os.stat(track_path).st_mtime) > track.last_modified:
|
||||
stat = os.stat(uri_path_mapping[track.uri])
|
||||
if int(stat.st_mtime) > track.last_modified:
|
||||
uris_to_update.add(track.uri)
|
||||
uris_in_library.add(track.uri)
|
||||
except OSError:
|
||||
@ -73,7 +74,7 @@ class ScanCommand(commands.Command):
|
||||
logger.debug('Skipped %s: File extension excluded.', uri)
|
||||
continue
|
||||
|
||||
uri = translator.path_to_local(relpath)
|
||||
uri = translator.path_to_local_track_uri(relpath)
|
||||
if uri not in uris_in_library:
|
||||
uris_to_update.add(uri)
|
||||
uri_path_mapping[uri] = os.path.join(media_dir, relpath)
|
||||
|
||||
@ -21,9 +21,6 @@ class Extension(ext.Extension):
|
||||
schema['json_file'] = config.Path()
|
||||
return schema
|
||||
|
||||
def validate_environment(self):
|
||||
pass
|
||||
|
||||
def get_backend_classes(self):
|
||||
from .actor import LocalJsonBackend
|
||||
return [LocalJsonBackend]
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import gzip
|
||||
|
||||
@ -19,9 +19,6 @@ class Extension(ext.Extension):
|
||||
# Config only contains local-tagcache/enabled since we are not setting our
|
||||
# own schema.
|
||||
|
||||
def validate_environment(self):
|
||||
pass
|
||||
|
||||
def get_backend_classes(self):
|
||||
from .actor import LocalTagcacheBackend
|
||||
return [LocalTagcacheBackend]
|
||||
|
||||
@ -5,8 +5,8 @@ import os
|
||||
import tempfile
|
||||
|
||||
from mopidy.backends import base
|
||||
from mopidy.backends.local.translator import local_to_file_uri
|
||||
from mopidy.backends.local import search
|
||||
from mopidy.backends.local.translator import local_to_file_uri
|
||||
|
||||
from .translator import parse_mpd_tag_cache, tracks_to_tag_cache_format
|
||||
|
||||
|
||||
@ -19,14 +19,15 @@ def local_to_file_uri(uri, media_dir):
|
||||
return path_to_uri(file_path)
|
||||
|
||||
|
||||
def local_to_path(uri, media_dir):
|
||||
def local_track_uri_to_path(uri, media_dir):
|
||||
if not uri.startswith('local:track:'):
|
||||
raise Exception
|
||||
raise ValueError('Invalid uri.')
|
||||
file_path = uri_to_path(uri).split(b':', 1)[1]
|
||||
return os.path.join(media_dir, file_path)
|
||||
|
||||
|
||||
def path_to_local(relpath):
|
||||
def path_to_local_track_uri(relpath):
|
||||
"""Convert path releative to media_dir to local track uri"""
|
||||
if isinstance(relpath, unicode):
|
||||
relpath = relpath.encode('utf-8')
|
||||
return b'local:track:%s' % urllib.quote(relpath)
|
||||
|
||||
@ -5,10 +5,10 @@ from __future__ import unicode_literals
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from mopidy.utils.path import mtime, uri_to_path
|
||||
from mopidy.frontends.mpd import translator as mpd, protocol
|
||||
from mopidy.backends.local.tagcache import translator
|
||||
from mopidy.frontends.mpd import translator as mpd, protocol
|
||||
from mopidy.models import Album, Artist, Track
|
||||
from mopidy.utils.path import mtime, uri_to_path
|
||||
|
||||
from tests import path_to_data_dir
|
||||
|
||||
|
||||
@ -37,12 +37,15 @@ class CoreActorTest(unittest.TestCase):
|
||||
Core, audio=None, backends=[self.backend1, self.backend2])
|
||||
|
||||
def test_backends_with_colliding_uri_schemes_passes(self):
|
||||
# Checks that backends with overlapping schemes, but distinct sub parts
|
||||
# provided can co-exist.
|
||||
"""
|
||||
Checks that backends with overlapping schemes, but distinct sub parts
|
||||
provided can co-exist.
|
||||
"""
|
||||
|
||||
self.backend1.has_library().get.return_value = False
|
||||
self.backend1.has_playlists().get.return_value = False
|
||||
|
||||
self.backend2.uri_schemes().get.return_value = ['dummy1']
|
||||
self.backend2.uri_schemes.get.return_value = ['dummy1']
|
||||
self.backend2.has_playback().get.return_value = False
|
||||
self.backend2.has_playlists().get.return_value = False
|
||||
|
||||
@ -50,4 +53,4 @@ class CoreActorTest(unittest.TestCase):
|
||||
self.assertEqual(core.backends.with_playback,
|
||||
{'dummy1': self.backend1})
|
||||
self.assertEqual(core.backends.with_library,
|
||||
{'dummy2': self.backend2})
|
||||
{'dummy1': self.backend2})
|
||||
|
||||
@ -225,8 +225,8 @@ class FindFilesTest(unittest.TestCase):
|
||||
|
||||
def test_files(self):
|
||||
files = self.find('find')
|
||||
excepted = [b'foo/bar/file', b'foo/file', b'baz/file']
|
||||
self.assertItemsEqual(excepted, files)
|
||||
expected = [b'foo/bar/file', b'foo/file', b'baz/file']
|
||||
self.assertItemsEqual(expected, files)
|
||||
|
||||
def test_names_are_bytestrings(self):
|
||||
is_bytes = lambda f: isinstance(f, bytes)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user