fix infinite-recursion regression in rewrite

Reported by axion on IRC.
This commit is contained in:
Adrian Sampson 2014-01-20 11:39:33 -08:00
parent 9162267960
commit 77daa542c8
2 changed files with 8 additions and 8 deletions

View file

@ -32,7 +32,7 @@ def rewriter(field, rules):
(pattern, replacement) pairs.
"""
def fieldfunc(item):
value = getattr(item, field)
value = item._values_fixed[field]
for pattern, replacement in rules:
if pattern.match(value.lower()):
# Rewrite activated.
@ -54,7 +54,7 @@ class RewritePlugin(BeetsPlugin):
fieldname, pattern = key.split(None, 1)
except ValueError:
raise ui.UserError("invalid rewrite specification")
if fieldname not in library.ITEM_KEYS:
if fieldname not in library.Item._fields:
raise ui.UserError("invalid field name (%s) in rewriter" %
fieldname)
log.debug(u'adding template field %s' % key)

View file

@ -1,10 +1,10 @@
Rewrite Plugin
==============
The ``rewrite`` plugin lets you easily substitute values in your path formats.
Specifically, it is intended to let you *canonicalize* names such as artists:
for example, perhaps you want albums from The Jimi Hendrix Experience to be
sorted into the same folder as solo Hendrix albums.
The ``rewrite`` plugin lets you easily substitute values in your templates and
path formats. Specifically, it is intended to let you *canonicalize* names
such as artists: for example, perhaps you want albums from The Jimi Hendrix
Experience to be sorted into the same folder as solo Hendrix albums.
To use field rewriting, first enable the plugin by putting ``rewrite`` on your
``plugins`` line. Then, make a ``rewrite:`` section in your config file to
@ -16,7 +16,7 @@ example above::
rewrite:
artist The Jimi Hendrix Experience: Jimi Hendrix
This will make ``$artist`` in your path formats expand to "Jimi Hendrix" where it
This will make ``$artist`` in your templates expand to "Jimi Hendrix" where it
would otherwise be "The Jimi Hendrix Experience".
The pattern is a case-insensitive regular expression. This means you can use
@ -30,5 +30,5 @@ As a convenience, the plugin applies patterns for the ``artist`` field to the
``albumartist`` field as well. (Otherwise, you would probably want to duplicate
every rule for ``artist`` and ``albumartist``.)
Note that this plugin only applies to path templating; it does not modify files'
Note that this plugin only applies to templating; it does not modify files'
metadata tags or the values tracked by beets' library database.