mirror of
https://github.com/beetbox/beets.git
synced 2025-12-28 11:32:30 +01:00
remove singleton enforcement from plugins
The plugin system itself now enforces single instances.
This commit is contained in:
parent
ebdbd69d8e
commit
58d9a775cc
5 changed files with 13 additions and 46 deletions
|
|
@ -44,6 +44,8 @@ class BeetsPlugin(object):
|
|||
self.import_stages = []
|
||||
self.name = name or self.__module__.split('.')[-1]
|
||||
self.config = beets.config[self.name]
|
||||
self.template_funcs = {}
|
||||
self.template_fields = {}
|
||||
|
||||
def commands(self):
|
||||
"""Should return a list of beets.ui.Subcommand objects for
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
import re
|
||||
import logging
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import config
|
||||
from beets.importer import action
|
||||
|
||||
|
||||
|
|
@ -39,14 +38,10 @@ class IHatePlugin(BeetsPlugin):
|
|||
skip_album = []
|
||||
skip_whitelist = []
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super(IHatePlugin,
|
||||
cls).__new__(cls, *args, **kwargs)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
super(IHatePlugin, self).__init__()
|
||||
self.register_listener('import_task_choice',
|
||||
self.import_task_choice_event)
|
||||
self.config.add({
|
||||
'warn_genre': [],
|
||||
'warn_artist': [],
|
||||
|
|
@ -98,7 +93,7 @@ class IHatePlugin(BeetsPlugin):
|
|||
('warn_genre', 'warn_artist', 'warn_album',
|
||||
'skip_genre', 'skip_artist', 'skip_album'))
|
||||
|
||||
def import_task_choice_event(self, task):
|
||||
def import_task_choice_event(self, session, task):
|
||||
if task.choice_flag == action.APPLY:
|
||||
if self.job_to_do():
|
||||
self._log.debug('[ihate] processing your hate')
|
||||
|
|
@ -122,8 +117,3 @@ class IHatePlugin(BeetsPlugin):
|
|||
self._log.debug('[ihate] nothing to do')
|
||||
else:
|
||||
self._log.debug('[ihate] user made a decision, nothing to do')
|
||||
|
||||
|
||||
@IHatePlugin.listen('import_task_choice')
|
||||
def ihate_import_task_choice(task, session):
|
||||
IHatePlugin().import_task_choice_event(task)
|
||||
|
|
|
|||
|
|
@ -36,15 +36,11 @@ class ThePlugin(BeetsPlugin):
|
|||
strip = False
|
||||
patterns = []
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super(ThePlugin,
|
||||
cls).__new__(cls, *args, **kwargs)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
super(ThePlugin, self).__init__()
|
||||
|
||||
self.template_funcs['the'] = self.the_template_func
|
||||
|
||||
self.config.add({
|
||||
'the': True,
|
||||
'a': True,
|
||||
|
|
@ -108,8 +104,3 @@ class ThePlugin(BeetsPlugin):
|
|||
return r
|
||||
else:
|
||||
return u''
|
||||
|
||||
@ThePlugin.template_func('the')
|
||||
def func_the(text):
|
||||
"""Provides beets template function %the"""
|
||||
return ThePlugin().the_template_func(text)
|
||||
|
|
|
|||
|
|
@ -30,15 +30,14 @@ class ZeroPlugin(BeetsPlugin):
|
|||
_instance = None
|
||||
_log = logging.getLogger('beets')
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super(ZeroPlugin,
|
||||
cls).__new__(cls, *args, **kwargs)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
super(ZeroPlugin, self).__init__()
|
||||
|
||||
# Listeners.
|
||||
self.register_listener('write', self.write_event)
|
||||
self.register_listener('import_task_choice',
|
||||
self.import_task_choice_event)
|
||||
|
||||
self.config.add({
|
||||
'fields': [],
|
||||
})
|
||||
|
|
@ -57,7 +56,7 @@ class ZeroPlugin(BeetsPlugin):
|
|||
except confit.NotFoundError:
|
||||
self.patterns[f] = [u'']
|
||||
|
||||
def import_task_choice_event(self, task):
|
||||
def import_task_choice_event(self, session, task):
|
||||
"""Listen for import_task_choice event."""
|
||||
if task.choice_flag == action.ASIS and not self.warned:
|
||||
self._log.warn(u'[zero] cannot zero in \"as-is\" mode')
|
||||
|
|
@ -95,12 +94,3 @@ class ZeroPlugin(BeetsPlugin):
|
|||
setattr(item, fn, type(fval)())
|
||||
self._log.debug(u'[zero] {0}={1}'
|
||||
.format(fn, getattr(item, fn)))
|
||||
|
||||
|
||||
@ZeroPlugin.listen('import_task_choice')
|
||||
def zero_choice(session, task):
|
||||
ZeroPlugin().import_task_choice_event(task)
|
||||
|
||||
@ZeroPlugin.listen('write')
|
||||
def zero_write(item):
|
||||
ZeroPlugin().write_event(item)
|
||||
|
|
|
|||
|
|
@ -6,12 +6,6 @@ from beetsplug.zero import ZeroPlugin
|
|||
|
||||
|
||||
class ZeroPluginTest(unittest.TestCase):
|
||||
|
||||
def test_singleton(self):
|
||||
z1 = ZeroPlugin()
|
||||
z2 = ZeroPlugin()
|
||||
self.assertTrue(z1 is z2)
|
||||
|
||||
def test_no_patterns(self):
|
||||
v = {'comments' : 'test comment',
|
||||
'day' : 13,
|
||||
|
|
|
|||
Loading…
Reference in a new issue