mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Automatic logger level changes on import
Breaking changes: plugins should set set _import_stages instead of import_stages. From outside the latter is replaced by import_stages(). This is because it is now wrapped with log level-getting & -setting statements.
This commit is contained in:
parent
d38d264b6b
commit
427f7e7035
10 changed files with 27 additions and 13 deletions
|
|
@ -18,6 +18,7 @@ import traceback
|
|||
import inspect
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from functools import wraps
|
||||
|
||||
|
||||
import beets
|
||||
|
|
@ -51,7 +52,7 @@ class BeetsPlugin(object):
|
|||
def __init__(self, name=None):
|
||||
"""Perform one-time plugin setup.
|
||||
"""
|
||||
self.import_stages = []
|
||||
self._import_stages = []
|
||||
self.name = name or self.__module__.split('.')[-1]
|
||||
self.config = beets.config[self.name]
|
||||
if not self.template_funcs:
|
||||
|
|
@ -63,7 +64,7 @@ class BeetsPlugin(object):
|
|||
|
||||
logger_name = '{0}.{1}'.format('beets', self.name)
|
||||
self._log = logging.getLogger(logger_name)
|
||||
self._log.setLevel(logging.WARNING)
|
||||
self._log.setLevel(logging.INFO)
|
||||
|
||||
def commands(self):
|
||||
"""Should return a list of beets.ui.Subcommand objects for
|
||||
|
|
@ -71,6 +72,20 @@ class BeetsPlugin(object):
|
|||
"""
|
||||
return ()
|
||||
|
||||
def import_stages(self):
|
||||
return [self._set_log_level(logging.WARNING, import_stage)
|
||||
for import_stage in self._import_stages]
|
||||
|
||||
def _set_log_level(self, log_level, func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
old_log_level = self._log.getEffectiveLevel()
|
||||
self._log.setLevel(log_level)
|
||||
result = func(*args, **kwargs)
|
||||
self._log.setLevel(old_log_level)
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
def queries(self):
|
||||
"""Should return a dict mapping prefixes to Query subclasses.
|
||||
"""
|
||||
|
|
@ -353,8 +368,7 @@ def import_stages():
|
|||
"""Get a list of import stage functions defined by plugins."""
|
||||
stages = []
|
||||
for plugin in find_plugins():
|
||||
if hasattr(plugin, 'import_stages'):
|
||||
stages += plugin.import_stages
|
||||
stages += plugin.import_stages()
|
||||
return stages
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -365,7 +365,7 @@ class ConvertPlugin(BeetsPlugin):
|
|||
u'never_convert_lossy_files': False,
|
||||
u'copy_album_art': False,
|
||||
})
|
||||
self.import_stages = [self.auto_convert]
|
||||
self._import_stages = [self.auto_convert]
|
||||
|
||||
def commands(self):
|
||||
cmd = ui.Subcommand('convert', help='convert to external location')
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin):
|
|||
config['echonest']['apikey'].get(unicode)
|
||||
|
||||
if self.config['auto']:
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
|
||||
def _echofun(self, func, **kwargs):
|
||||
"""Wrapper for requests to the EchoNest API. Will retry up to
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ class FetchArtPlugin(plugins.BeetsPlugin):
|
|||
self.maxwidth = self.config['maxwidth'].get(int)
|
||||
if self.config['auto']:
|
||||
# Enable two import hooks when fetching is enabled.
|
||||
self.import_stages = [self.fetch_art]
|
||||
self._import_stages = [self.fetch_art]
|
||||
self.register_listener('import_task_files', self.assign_art)
|
||||
|
||||
available_sources = list(SOURCES_ALL)
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class FtInTitlePlugin(plugins.BeetsPlugin):
|
|||
help='drop featuring from artists and ignore title update')
|
||||
|
||||
if self.config['auto']:
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
|
||||
def commands(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class KeyFinderPlugin(BeetsPlugin):
|
|||
u'overwrite': False,
|
||||
})
|
||||
self.config['auto'].get(bool)
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
|
||||
def commands(self):
|
||||
cmd = ui.Subcommand('keyfinder',
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
"""Setup plugin from config options
|
||||
"""
|
||||
if self.config['auto']:
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
|
||||
self._genre_cache = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ SOURCE_BACKENDS = {
|
|||
class LyricsPlugin(plugins.BeetsPlugin):
|
||||
def __init__(self):
|
||||
super(LyricsPlugin, self).__init__()
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
self.config.add({
|
||||
'auto': True,
|
||||
'google_API_key': None,
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ class MusicBrainzCollectionPlugin(BeetsPlugin):
|
|||
)
|
||||
self.config.add({'auto': False})
|
||||
if self.config['auto']:
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
|
||||
def commands(self):
|
||||
return [update_mb_collection_cmd]
|
||||
|
|
|
|||
|
|
@ -601,7 +601,7 @@ class ReplayGainPlugin(BeetsPlugin):
|
|||
|
||||
def __init__(self):
|
||||
super(ReplayGainPlugin, self).__init__()
|
||||
self.import_stages = [self.imported]
|
||||
self._import_stages = [self.imported]
|
||||
|
||||
# default backend is 'command' for backward-compatibility.
|
||||
self.config.add({
|
||||
|
|
|
|||
Loading…
Reference in a new issue