tagcache: Split out to own extension for eventual deletion.
This commit is contained in:
parent
3c1c6bac71
commit
c025b87076
@ -33,10 +33,6 @@ class Extension(ext.Extension):
|
||||
from .actor import LocalBackend
|
||||
return [LocalBackend]
|
||||
|
||||
def get_library_updaters(self):
|
||||
from .tagcache.library import LocalLibraryUpdateProvider
|
||||
return [LocalLibraryUpdateProvider]
|
||||
|
||||
def get_command(self):
|
||||
from .commands import LocalCommand
|
||||
return LocalCommand()
|
||||
|
||||
@ -8,7 +8,6 @@ import pykka
|
||||
from mopidy.backends import base
|
||||
from mopidy.utils import encoding, path
|
||||
|
||||
from .tagcache.library import LocalLibraryProvider
|
||||
from .playlists import LocalPlaylistsProvider
|
||||
from .playback import LocalPlaybackProvider
|
||||
|
||||
@ -23,7 +22,6 @@ class LocalBackend(pykka.ThreadingActor, base.Backend):
|
||||
|
||||
self.check_dirs_and_files()
|
||||
|
||||
self.library = LocalLibraryProvider(backend=self)
|
||||
self.playback = LocalPlaybackProvider(audio=audio, backend=self)
|
||||
self.playlists = LocalPlaylistsProvider(backend=self)
|
||||
|
||||
@ -40,10 +38,3 @@ class LocalBackend(pykka.ThreadingActor, base.Backend):
|
||||
logger.warning(
|
||||
'Could not create local playlists dir: %s',
|
||||
encoding.locale_decode(error))
|
||||
|
||||
try:
|
||||
path.get_or_create_file(self.config['local']['tag_cache_file'])
|
||||
except EnvironmentError as error:
|
||||
logger.warning(
|
||||
'Could not create empty tag cache file: %s',
|
||||
encoding.locale_decode(error))
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import mopidy
|
||||
from mopidy import config, ext
|
||||
|
||||
|
||||
class Extension(ext.Extension):
|
||||
|
||||
dist_name = 'Mopidy-Local-Tagcache'
|
||||
ext_name = 'local-tagcache'
|
||||
version = mopidy.__version__
|
||||
|
||||
def get_default_config(self):
|
||||
conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf')
|
||||
return config.read(conf_file)
|
||||
|
||||
# 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]
|
||||
|
||||
def get_library_updaters(self):
|
||||
from .library import LocalTagcacheLibraryUpdateProvider
|
||||
return [LocalTagcacheLibraryUpdateProvider]
|
||||
30
mopidy/backends/local/tagcache/actor.py
Normal file
30
mopidy/backends/local/tagcache/actor.py
Normal file
@ -0,0 +1,30 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
import pykka
|
||||
|
||||
from mopidy.backends import base
|
||||
from mopidy.utils import encoding, path
|
||||
|
||||
from .library import LocalTagcacheLibraryProvider
|
||||
|
||||
logger = logging.getLogger('mopidy.backends.local.tagcache')
|
||||
|
||||
|
||||
class LocalTagcacheBackend(pykka.ThreadingActor, base.Backend):
|
||||
def __init__(self, config, audio):
|
||||
super(LocalTagcacheBackend, self).__init__()
|
||||
|
||||
self.config = config
|
||||
self.check_dirs_and_files()
|
||||
self.library = LocalTagcacheLibraryProvider(backend=self)
|
||||
self.uri_schemes = ['local']
|
||||
|
||||
def check_dirs_and_files(self):
|
||||
try:
|
||||
path.get_or_create_file(self.config['local']['tag_cache_file'])
|
||||
except EnvironmentError as error:
|
||||
logger.warning(
|
||||
'Could not create empty tag cache file: %s',
|
||||
encoding.locale_decode(error))
|
||||
2
mopidy/backends/local/tagcache/ext.conf
Normal file
2
mopidy/backends/local/tagcache/ext.conf
Normal file
@ -0,0 +1,2 @@
|
||||
[local-tagcache]
|
||||
enabled = true
|
||||
@ -13,9 +13,9 @@ from .translator import parse_mpd_tag_cache, tracks_to_tag_cache_format
|
||||
logger = logging.getLogger('mopidy.backends.local.tagcache')
|
||||
|
||||
|
||||
class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
class LocalTagcacheLibraryProvider(base.BaseLibraryProvider):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LocalLibraryProvider, self).__init__(*args, **kwargs)
|
||||
super(LocalTagcacheLibraryProvider, self).__init__(*args, **kwargs)
|
||||
self._uri_mapping = {}
|
||||
self._media_dir = self.backend.config['local']['media_dir']
|
||||
self._tag_cache_file = self.backend.config['local']['tag_cache_file']
|
||||
@ -219,7 +219,7 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
raise LookupError('Missing query')
|
||||
|
||||
|
||||
class LocalLibraryUpdateProvider(base.BaseLibraryProvider):
|
||||
class LocalTagcacheLibraryUpdateProvider(base.BaseLibraryProvider):
|
||||
uri_schemes = ['local']
|
||||
|
||||
def __init__(self, config):
|
||||
|
||||
1
setup.py
1
setup.py
@ -43,6 +43,7 @@ setup(
|
||||
'mopidy.ext': [
|
||||
'http = mopidy.frontends.http:Extension [http]',
|
||||
'local = mopidy.backends.local:Extension',
|
||||
'local-tagcache = mopidy.backends.local.tagcache:Extension',
|
||||
'mpd = mopidy.frontends.mpd:Extension',
|
||||
'stream = mopidy.backends.stream:Extension',
|
||||
],
|
||||
|
||||
@ -6,7 +6,7 @@ import unittest
|
||||
import pykka
|
||||
|
||||
from mopidy import core
|
||||
from mopidy.backends.local import actor
|
||||
from mopidy.backends.local.tagcache import actor
|
||||
from mopidy.models import Track, Album, Artist
|
||||
|
||||
from tests import path_to_data_dir
|
||||
@ -66,7 +66,7 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.backend = actor.LocalBackend.start(
|
||||
self.backend = actor.LocalTagcacheBackend.start(
|
||||
config=self.config, audio=None).proxy()
|
||||
self.core = core.Core(backends=[self.backend])
|
||||
self.library = self.core.library
|
||||
@ -92,7 +92,7 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
||||
|
||||
config = {'local': self.config['local'].copy()}
|
||||
config['local']['tag_cache_file'] = tag_cache.name
|
||||
backend = actor.LocalBackend(config=config, audio=None)
|
||||
backend = actor.LocalTagcacheBackend(config=config, audio=None)
|
||||
|
||||
# Sanity check that value is in tag cache
|
||||
result = backend.library.lookup(self.tracks[0].uri)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user