mirror of
https://github.com/beetbox/beets.git
synced 2025-12-14 04:23:56 +01:00
Refactor _load_plugins
Move configuration validation into `confit`. Get rid of dependency on global configuration object.
This commit is contained in:
parent
68bc77362b
commit
a0cf1f30e3
2 changed files with 26 additions and 16 deletions
|
|
@ -499,14 +499,6 @@ def get_plugin_paths():
|
|||
The value for "pluginpath" may be a single string or a list of
|
||||
strings.
|
||||
"""
|
||||
pluginpaths = config['pluginpath'].get()
|
||||
if isinstance(pluginpaths, basestring):
|
||||
pluginpaths = [pluginpaths]
|
||||
if not isinstance(pluginpaths, list):
|
||||
raise confit.ConfigTypeError(
|
||||
u'pluginpath must be string or a list of strings'
|
||||
)
|
||||
return map(util.normpath, pluginpaths)
|
||||
|
||||
|
||||
def _pick_format(album, fmt=None):
|
||||
|
|
@ -850,19 +842,20 @@ def vararg_callback(option, opt_str, value, parser):
|
|||
|
||||
# The main entry point and bootstrapping.
|
||||
|
||||
def _load_plugins():
|
||||
def _load_plugins(config):
|
||||
"""Load the plugins specified in the configuration.
|
||||
"""
|
||||
# Add plugin paths.
|
||||
paths = config['pluginpath'].get(confit.EnsureStringList())
|
||||
paths = map(util.normpath, paths)
|
||||
|
||||
import beetsplug
|
||||
beetsplug.__path__ = get_plugin_paths() + beetsplug.__path__
|
||||
|
||||
beetsplug.__path__ = paths + beetsplug.__path__
|
||||
# For backwards compatibility.
|
||||
sys.path += get_plugin_paths()
|
||||
sys.path += paths
|
||||
|
||||
# Load requested plugins.
|
||||
plugins.load_plugins(config['plugins'].as_str_seq())
|
||||
plugins.send("pluginload")
|
||||
return plugins
|
||||
|
||||
|
||||
def _setup(options, lib=None):
|
||||
|
|
@ -873,9 +866,9 @@ def _setup(options, lib=None):
|
|||
# Configure the MusicBrainz API.
|
||||
mb.configure()
|
||||
|
||||
_configure(options)
|
||||
config = _configure(options)
|
||||
|
||||
_load_plugins()
|
||||
plugins = _load_plugins(config)
|
||||
|
||||
# Temporary: Migrate from 1.0-style configuration.
|
||||
from beets.ui import migrate
|
||||
|
|
@ -924,6 +917,7 @@ def _configure(options):
|
|||
|
||||
log.debug(u'data directory: {0}'
|
||||
.format(util.displayable_path(config.config_dir())))
|
||||
return config
|
||||
|
||||
|
||||
def _open_library(config):
|
||||
|
|
|
|||
|
|
@ -1073,6 +1073,22 @@ class StrSeq(Template):
|
|||
self.fail('must be a list of strings', view, True)
|
||||
|
||||
|
||||
class EnsureStringList(Template):
|
||||
"""Always return a list of strings.
|
||||
|
||||
The raw value may either be a single string or a list of strings.
|
||||
Otherwise a type error is raised. For single strings a singleton
|
||||
list is returned.
|
||||
"""
|
||||
def convert(self, paths, view):
|
||||
if isinstance(paths, basestring):
|
||||
paths = [paths]
|
||||
if not isinstance(paths, list) or \
|
||||
not all(map(lambda p: isinstance(p, basestring), paths)):
|
||||
self.fail(u'must be string or a list of strings', view, True)
|
||||
return paths
|
||||
|
||||
|
||||
class Filename(Template):
|
||||
"""A template that validates strings as filenames.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue