From 69c3e107a20fe9df0f6612cd72b7ba85b420c084 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 29 Aug 2014 14:02:08 +0200 Subject: [PATCH] local: Add ROOT_DIRECTORY_URI constant Related to #833 --- docs/changelog.rst | 4 ++++ mopidy/local/__init__.py | 12 ++++++++++++ mopidy/local/json.py | 7 +++---- mopidy/local/library.py | 6 +++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6ef9393e..bc7c0e73 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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) ==================== diff --git a/mopidy/local/__init__.py b/mopidy/local/__init__.py index da4d8a55..7f4cd03f 100644 --- a/mopidy/local/__init__.py +++ b/mopidy/local/__init__.py @@ -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. """ diff --git a/mopidy/local/json.py b/mopidy/local/json.py index 927f8898..1bb55389 100644 --- a/mopidy/local/json.py +++ b/mopidy/local/json.py @@ -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 diff --git a/mopidy/local/library.py b/mopidy/local/library.py index 65aa4268..cf312883 100644 --- a/mopidy/local/library.py +++ b/mopidy/local/library.py @@ -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)