parent
5ad76abc3d
commit
f655fc7009
@ -28,6 +28,12 @@ Bug fix release.
|
||||
- Core: Fix error in :meth:`~mopidy.core.TracklistController.get_eot_tlid`
|
||||
docstring. (Fixes: :issue:`1269`)
|
||||
|
||||
- Extension support: Make :meth:`~mopidy.ext.Extension.get_cache_dir`,
|
||||
:meth:`~mopidy.ext.Extension.get_config_dir`, and
|
||||
:meth:`~mopidy.ext.Extension.get_data_dir` class methods, so they can be used
|
||||
without creating an instance of the :class:`~mopidy.ext.Extension` class.
|
||||
(Fixes: :issue:`1275`)
|
||||
|
||||
- Local: Deprecate :confval:`local/data_dir` and respect
|
||||
:confval:`core/data_dir` instead. This does not change the defaults for
|
||||
desktop users, only system services installed from packages that properly set
|
||||
|
||||
@ -60,7 +60,8 @@ class Extension(object):
|
||||
schema['enabled'] = config_lib.Boolean()
|
||||
return schema
|
||||
|
||||
def get_cache_dir(self, config):
|
||||
@classmethod
|
||||
def get_cache_dir(cls, config):
|
||||
"""Get or create cache directory for the extension.
|
||||
|
||||
Use this directory to cache data that can safely be thrown away.
|
||||
@ -68,25 +69,27 @@ class Extension(object):
|
||||
:param config: the Mopidy config object
|
||||
:return: string
|
||||
"""
|
||||
assert self.ext_name is not None
|
||||
assert cls.ext_name is not None
|
||||
cache_dir_path = bytes(os.path.join(config['core']['cache_dir'],
|
||||
self.ext_name))
|
||||
cls.ext_name))
|
||||
path.get_or_create_dir(cache_dir_path)
|
||||
return cache_dir_path
|
||||
|
||||
def get_config_dir(self, config):
|
||||
@classmethod
|
||||
def get_config_dir(cls, config):
|
||||
"""Get or create configuration directory for the extension.
|
||||
|
||||
:param config: the Mopidy config object
|
||||
:return: string
|
||||
"""
|
||||
assert self.ext_name is not None
|
||||
assert cls.ext_name is not None
|
||||
config_dir_path = bytes(os.path.join(config['core']['config_dir'],
|
||||
self.ext_name))
|
||||
cls.ext_name))
|
||||
path.get_or_create_dir(config_dir_path)
|
||||
return config_dir_path
|
||||
|
||||
def get_data_dir(self, config):
|
||||
@classmethod
|
||||
def get_data_dir(cls, config):
|
||||
"""Get or create data directory for the extension.
|
||||
|
||||
Use this directory to store data that should be persistent.
|
||||
@ -94,9 +97,9 @@ class Extension(object):
|
||||
:param config: the Mopidy config object
|
||||
:returns: string
|
||||
"""
|
||||
assert self.ext_name is not None
|
||||
assert cls.ext_name is not None
|
||||
data_dir_path = bytes(os.path.join(config['core']['data_dir'],
|
||||
self.ext_name))
|
||||
cls.ext_name))
|
||||
path.get_or_create_dir(data_dir_path)
|
||||
return data_dir_path
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import tempfile
|
||||
import mopidy
|
||||
from mopidy import compat, local, models
|
||||
from mopidy.internal import encoding, timer
|
||||
from mopidy.local import Extension, search, storage, translator
|
||||
from mopidy.local import search, storage, translator
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -116,7 +116,7 @@ class JsonLibrary(local.Library):
|
||||
self._browse_cache = None
|
||||
self._media_dir = config['local']['media_dir']
|
||||
self._json_file = os.path.join(
|
||||
Extension().get_data_dir(config), b'library.json.gz')
|
||||
local.Extension.get_data_dir(config), b'library.json.gz')
|
||||
|
||||
storage.check_dirs_and_files(config)
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ class M3UBackend(pykka.ThreadingActor, backend.Backend):
|
||||
'Could not create M3U playlists dir: %s',
|
||||
encoding.locale_decode(error))
|
||||
else:
|
||||
self._playlists_dir = m3u.Extension().get_data_dir(config)
|
||||
self._playlists_dir = m3u.Extension.get_data_dir(config)
|
||||
|
||||
self.playlists = M3UPlaylistsProvider(backend=self)
|
||||
self.library = M3ULibraryProvider(backend=self)
|
||||
|
||||
@ -58,17 +58,17 @@ class TestExtension(object):
|
||||
def test_get_cache_dir_raises_assertion_error(self, extension):
|
||||
config = {'core': {'cache_dir': '/tmp'}}
|
||||
with pytest.raises(AssertionError): # ext_name not set
|
||||
extension.get_cache_dir(config)
|
||||
ext.Extension.get_cache_dir(config)
|
||||
|
||||
def test_get_config_dir_raises_assertion_error(self, extension):
|
||||
config = {'core': {'config_dir': '/tmp'}}
|
||||
with pytest.raises(AssertionError): # ext_name not set
|
||||
extension.get_config_dir(config)
|
||||
ext.Extension.get_config_dir(config)
|
||||
|
||||
def test_get_data_dir_raises_assertion_error(self, extension):
|
||||
config = {'core': {'data_dir': '/tmp'}}
|
||||
with pytest.raises(AssertionError): # ext_name not set
|
||||
extension.get_data_dir(config)
|
||||
ext.Extension.get_data_dir(config)
|
||||
|
||||
|
||||
class TestLoadExtensions(object):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user