local: Create all needed dirs/files on startup

This commit is contained in:
Stein Magnus Jodal 2013-04-09 12:51:34 +02:00
parent bc959e2240
commit bf83a159fe
2 changed files with 28 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import logging
import pykka
from mopidy.backends import base
from mopidy.utils import encoding, path
from .library import LocalLibraryProvider
from .playlists import LocalPlaylistsProvider
@ -18,8 +19,32 @@ class LocalBackend(pykka.ThreadingActor, base.Backend):
self.config = config
self.create_dirs_and_files()
self.library = LocalLibraryProvider(backend=self)
self.playback = base.BasePlaybackProvider(audio=audio, backend=self)
self.playlists = LocalPlaylistsProvider(backend=self)
self.uri_schemes = ['file']
def create_dirs_and_files(self):
try:
path.get_or_create_dir(self.config['local']['media_dir'])
except EnvironmentError as error:
logger.warning(
'Could not create local media dir: %s',
encoding.locale_decode(error))
try:
path.get_or_create_dir(self.config['local']['playlists_dir'])
except EnvironmentError as error:
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))

View File

@ -3,7 +3,6 @@ from __future__ import unicode_literals
import logging
from mopidy.backends import base
from mopidy.models import Album, SearchResult
from mopidy.utils import encoding, path
from .translator import parse_mpd_tag_cache
@ -19,13 +18,9 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
self.refresh()
def refresh(self, uri=None):
try:
path.get_or_create_file(self._tag_cache_file)
except EnvironmentError as error:
logger.warning(
'Could not create empty tag cache: %s',
encoding.locale_decode(error))
return
logger.debug(
'Loading local tracks from %s using %s',
self._media_dir, self._tag_cache_file)
tracks = parse_mpd_tag_cache(self._tag_cache_file, self._media_dir)