local: Add ROOT_DIRECTORY_URI constant

Related to #833
This commit is contained in:
Stein Magnus Jodal 2014-08-29 14:02:08 +02:00
parent 0e60730704
commit 69c3e107a2
4 changed files with 22 additions and 7 deletions

View File

@ -28,6 +28,10 @@ Bug fix release.
and docs to match how the core use the backend's browse method. (Fixes:
:issue:`833`)
- Local library API: Add :attr:`mopidy.local.ROOT_DIRECTORY_URI` constant for
use by implementors of :method:`mopidy.local.Library.browse`. (Related to:
:issue:`833`)
v0.19.3 (2014-08-03)
====================

View File

@ -46,6 +46,15 @@ class Extension(ext.Extension):
return LocalCommand()
ROOT_DIRECTORY_URI = 'local:directory'
"""
URI of the local backend's root directory.
This constant should be used by libraries implementing the
:meth:`Library.browse` method.
"""
class Library(object):
"""
Local library interface.
@ -68,6 +77,9 @@ class Library(object):
"""
Browse directories and tracks at the given URI.
The URI for the root directory is a constant available at
:attr:`ROOT_DIRECTORY_URI`.
:param string path: URI to browse.
:rtype: List of :class:`~mopidy.models.Ref` tracks and directories.
"""

View File

@ -61,8 +61,7 @@ class _BrowseCache(object):
splitpath_re = re.compile(r'([^/]+)')
def __init__(self, uris):
# TODO: local.ROOT_DIRECTORY_URI
self._cache = {'local:directory': collections.OrderedDict()}
self._cache = {local.ROOT_DIRECTORY_URI: collections.OrderedDict()}
for track_uri in uris:
path = translator.local_track_uri_to_path(track_uri, b'/')
@ -97,10 +96,10 @@ class _BrowseCache(object):
else:
# Loop completed, so final child needs to be added to root.
if child:
self._cache['local:directory'][child.uri] = child
self._cache[local.ROOT_DIRECTORY_URI][child.uri] = child
# If no parent was set we belong in the root.
if not parent_uri:
parent_uri = 'local:directory'
parent_uri = local.ROOT_DIRECTORY_URI
self._cache[parent_uri][track_uri] = track_ref

View File

@ -2,7 +2,7 @@ from __future__ import unicode_literals
import logging
from mopidy import backend, models
from mopidy import backend, local, models
logger = logging.getLogger(__name__)
@ -10,8 +10,8 @@ logger = logging.getLogger(__name__)
class LocalLibraryProvider(backend.LibraryProvider):
"""Proxy library that delegates work to our active local library."""
root_directory = models.Ref.directory(uri=b'local:directory',
name='Local media')
root_directory = models.Ref.directory(
uri=local.ROOT_DIRECTORY_URI, name='Local media')
def __init__(self, backend, library):
super(LocalLibraryProvider, self).__init__(backend)