inline: rename "pathfields" to "item_fields"

This commit is contained in:
Adrian Sampson 2013-05-28 23:20:19 -07:00
parent 0176e10ccf
commit 3b438b7778
3 changed files with 15 additions and 9 deletions

View file

@ -16,6 +16,7 @@
"""
import logging
import traceback
import itertools
from beets.plugins import BeetsPlugin
from beets import config
@ -101,17 +102,20 @@ class InlinePlugin(BeetsPlugin):
super(InlinePlugin, self).__init__()
config.add({
'pathfields': {},
'pathfields': {}, # Legacy name.
'item_fields': {},
'album_fields': {},
})
# Add field expressions.
for key, view in config['pathfields'].items():
# Item fields.
for key, view in itertools.chain(config['item_fields'].items(),
config['pathfields'].items()):
log.debug(u'inline: adding item field %s' % key)
func = compile_inline(view.get(unicode), False)
if func is not None:
self.template_fields[key] = func
# Album fields.
for key, view in config['album_fields'].items():
log.debug(u'inline: adding album field %s' % key)
func = compile_inline(view.get(unicode), True)

View file

@ -33,7 +33,9 @@ Changelog
to some fixes in dealing with special characters.
* Plugins can now provide fields for both Album and Item templates, thanks
to Pedro Silva. Accordingly, the :doc:`/plugins/inline` can also now define
album fields.
album fields. For consistency, the ``pathfields`` configuration section has
been renamed ``item_fields`` (although the old name will still work for
compatibility).
* The :ref:`fields-cmd` command shows template fields provided by plugins.
Thanks again to Pedro Silva.
* Album art filenames now respect the :ref:`replace` configuration.

View file

@ -8,7 +8,7 @@ to them from your template strings in the ``[paths]`` section (see
To use inline field definitions, first enable the plugin by putting ``inline``
on your ``plugins`` line in your configuration file. Then, make a
``pathfields:`` block in your config file. Under this key, every line defines a
``item_fields:`` block in your config file. Under this key, every line defines a
new template field; the key is the name of the field (you'll use the name to
refer to the field in your templates) and the value is a Python expression or
function body. The Python code has all of a track's fields in scope, so you can
@ -17,7 +17,7 @@ variables.
Here are a couple of examples of expressions::
pathfields:
item_fields:
initial: albumartist[0].upper() + u'.'
disc_and_track: u'%02i.%02i' % (disc, track) if
disctotal > 1 else u'%02i' % (track)
@ -32,14 +32,14 @@ referenced in path templates like so::
default: $initial/$artist/$album%aunique{}/$disc_and_track $title
Function Fields
---------------
Block Definitions
-----------------
If you need to use statements like ``import``, you can write a Python function
body instead of a single expression. In this case, you'll need to ``return``
a result for the value of the path field, like so::
pathfields:
item_fields:
filename: |
import os
from beets.util import bytestring_path