backend/core: Switch to root_directory instead of name
This commit is contained in:
parent
ba87613fd1
commit
826419d829
@ -52,9 +52,12 @@ class LibraryProvider(object):
|
||||
|
||||
pykka_traversable = True
|
||||
|
||||
root_directory_name = None
|
||||
root_directory = None
|
||||
"""
|
||||
Name of the library's root directory in Mopidy's virtual file system.
|
||||
:class:`models.Ref.directory` instance with an uri and name set
|
||||
representing the root of this libraries browse tree. URIs must
|
||||
use one of the schemes supported by the backend, and name should
|
||||
be set to a human friendly value.
|
||||
|
||||
*MUST be set by any class that implements :meth:`LibraryProvider.browse`.*
|
||||
"""
|
||||
|
||||
@ -115,6 +115,6 @@ class Backends(list):
|
||||
self.with_playlists[scheme] = backend
|
||||
|
||||
if has_library:
|
||||
root_dir_name = backend.library.root_directory_name.get()
|
||||
if root_dir_name is not None:
|
||||
self.with_browsable_library[root_dir_name] = backend
|
||||
root_dir = backend.library.root_directory.get()
|
||||
if root_dir is not None:
|
||||
self.with_browsable_library[root_dir] = backend
|
||||
|
||||
@ -64,10 +64,14 @@ class LibraryController(object):
|
||||
if not path.startswith('/'):
|
||||
return []
|
||||
|
||||
mapping = {}
|
||||
for ref in self.backends.with_browsable_library.keys():
|
||||
name = urlparse.urlparse(ref.uri).scheme
|
||||
mapping[name] = ref
|
||||
|
||||
if path == '/':
|
||||
return [
|
||||
Ref.directory(uri='/%s' % name, name=name)
|
||||
for name in self.backends.with_browsable_library.keys()]
|
||||
return [Ref.directory(uri='/%s' % name, name=name)
|
||||
for name in sorted(mapping)]
|
||||
|
||||
groups = re.match('/(?P<library>[^/]+)(?P<path>.*)', path).groupdict()
|
||||
library_name = groups['library']
|
||||
@ -75,7 +79,8 @@ class LibraryController(object):
|
||||
if not backend_path.startswith('/'):
|
||||
backend_path = '/%s' % backend_path
|
||||
|
||||
backend = self.backends.with_browsable_library.get(library_name, None)
|
||||
backend = self.backends.with_browsable_library.get(
|
||||
mapping.get(library_name), None)
|
||||
if not backend:
|
||||
return []
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from mopidy import backend
|
||||
from mopidy import backend, models
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -10,7 +10,8 @@ logger = logging.getLogger(__name__)
|
||||
class LocalLibraryProvider(backend.LibraryProvider):
|
||||
"""Proxy library that delegates work to our active local library."""
|
||||
|
||||
root_directory_name = 'local'
|
||||
root_directory = models.Ref.directory(uri=b'local:directory',
|
||||
name='Local media')
|
||||
|
||||
def __init__(self, backend, library):
|
||||
super(LocalLibraryProvider, self).__init__(backend)
|
||||
|
||||
@ -9,16 +9,18 @@ from mopidy.models import Ref, SearchResult, Track
|
||||
|
||||
class CoreLibraryTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
dummy1_root = Ref.directory(uri='dummy1:directory', name='dummy1')
|
||||
self.backend1 = mock.Mock()
|
||||
self.backend1.uri_schemes.get.return_value = ['dummy1']
|
||||
self.library1 = mock.Mock(spec=backend.LibraryProvider)
|
||||
self.library1.root_directory_name.get.return_value = 'dummy1'
|
||||
self.library1.root_directory.get.return_value = dummy1_root
|
||||
self.backend1.library = self.library1
|
||||
|
||||
dummy2_root = Ref.directory(uri='dummy2:directory', name='dummy2')
|
||||
self.backend2 = mock.Mock()
|
||||
self.backend2.uri_schemes.get.return_value = ['dummy2']
|
||||
self.library2 = mock.Mock(spec=backend.LibraryProvider)
|
||||
self.library2.root_directory_name.get.return_value = 'dummy2'
|
||||
self.library2.root_directory.get.return_value = dummy2_root
|
||||
self.backend2.library = self.library2
|
||||
|
||||
# A backend without the optional library provider
|
||||
|
||||
@ -9,7 +9,7 @@ from __future__ import unicode_literals
|
||||
import pykka
|
||||
|
||||
from mopidy import backend
|
||||
from mopidy.models import Playlist, SearchResult
|
||||
from mopidy.models import Playlist, Ref, SearchResult
|
||||
|
||||
|
||||
def create_dummy_backend_proxy(config=None, audio=None):
|
||||
@ -28,7 +28,7 @@ class DummyBackend(pykka.ThreadingActor, backend.Backend):
|
||||
|
||||
|
||||
class DummyLibraryProvider(backend.LibraryProvider):
|
||||
root_directory_name = 'dummy'
|
||||
root_directory = Ref.directory(uri='dummy:directory', name='dummy')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DummyLibraryProvider, self).__init__(*args, **kwargs)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user