local: Created needed dirs when scanning (fix #703)

This commit is contained in:
Stein Magnus Jodal 2014-05-06 22:59:16 +02:00
parent 7ae9a045df
commit c7b3f4a978
3 changed files with 10 additions and 27 deletions

View File

@ -59,6 +59,11 @@ Feature release.
and check files' modification time. This speeds up scanning, escpecially
when scanning remote file systems over e.g. NFS.
- the ``local scan`` command now creates necessary folders if they don't
already exist. Previously, this was only done by the Mopidy server, so doing
a ``local scan`` before running the server the first time resulted in a
crash. (Fixes: :issue:`703`)
v0.18.3 (2014-02-16)
====================

View File

@ -1,13 +1,12 @@
from __future__ import unicode_literals
import logging
import os
import pykka
from mopidy import backend
from mopidy.utils import encoding, path
from . import storage
from .library import LocalLibraryProvider
from .playback import LocalPlaybackProvider
from .playlists import LocalPlaylistsProvider
@ -24,7 +23,7 @@ class LocalBackend(pykka.ThreadingActor, backend.Backend):
self.config = config
self.check_dirs_and_files()
storage.check_dirs_and_files(config)
libraries = dict((l.name, l) for l in self.libraries)
library_name = config['local']['library']
@ -39,23 +38,3 @@ class LocalBackend(pykka.ThreadingActor, backend.Backend):
self.playback = LocalPlaybackProvider(audio=audio, backend=self)
self.playlists = LocalPlaylistsProvider(backend=self)
self.library = LocalLibraryProvider(backend=self, library=library)
def check_dirs_and_files(self):
if not os.path.isdir(self.config['local']['media_dir']):
logger.warning('Local media dir %s does not exist.' %
self.config['local']['media_dir'])
try:
path.get_or_create_dir(self.config['local']['data_dir'])
except EnvironmentError as error:
logger.warning(
'Could not create local data dir: %s',
encoding.locale_decode(error))
# TODO: replace with data dir?
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))

View File

@ -12,7 +12,7 @@ import time
import mopidy
from mopidy import local, models
from mopidy.local import search, translator
from mopidy.local import search, storage, translator
logger = logging.getLogger(__name__)
@ -31,9 +31,6 @@ def write_library(json_file, data):
data['version'] = mopidy.__version__
directory, basename = os.path.split(json_file)
if not os.path.exists(directory):
os.makedirs(directory)
# TODO: cleanup directory/basename.* files.
tmp = tempfile.NamedTemporaryFile(
prefix=basename + '.', dir=directory, delete=False)
@ -124,6 +121,8 @@ class JsonLibrary(local.Library):
self._json_file = os.path.join(
config['local']['data_dir'], b'library.json.gz')
storage.check_dirs_and_files(config)
def browse(self, uri):
if not self._browse_cache:
return []