fix inline and rewrite for instance fields

I'm transitioning to using exclusively instance-level fields instead of
class-level fields in plugin objects, but I neglected to bring inline and
rewrite into the future. This manifested as silent inaction on the part of
these plugins.

This change restores the old behavior (for compatibility) but also updates the
plugins to use the new behavior.
This commit is contained in:
Adrian Sampson 2013-02-02 08:35:54 -08:00
parent e850e1aab8
commit 887d1c1287
3 changed files with 6 additions and 8 deletions

View file

@ -44,8 +44,10 @@ 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 = {}
if not self.template_funcs:
self.template_funcs = {}
if not self.template_fields:
self.template_fields = {}
def commands(self):
"""Should return a list of beets.ui.Subcommand objects for

View file

@ -89,8 +89,6 @@ def compile_inline(python_code):
return _func_func
class InlinePlugin(BeetsPlugin):
template_fields = {}
def __init__(self):
super(InlinePlugin, self).__init__()
@ -103,4 +101,4 @@ class InlinePlugin(BeetsPlugin):
log.debug(u'adding template field %s' % key)
func = compile_inline(view.get(unicode))
if func is not None:
InlinePlugin.template_fields[key] = func
self.template_fields[key] = func

View file

@ -44,7 +44,6 @@ def rewriter(field, rules):
class RewritePlugin(BeetsPlugin):
def __init__(self):
super(RewritePlugin, self).__init__()
BeetsPlugin.template_fields = {}
self.config.add({})
@ -68,5 +67,4 @@ class RewritePlugin(BeetsPlugin):
# Replace each template field with the new rewriter function.
for fieldname, fieldrules in rules.iteritems():
RewritePlugin.template_fields[fieldname] = \
rewriter(fieldname, fieldrules)
self.template_fields[fieldname] = rewriter(fieldname, fieldrules)