From 3b438b77780c9d1540bc1abafff736a84baac6d6 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 28 May 2013 23:20:19 -0700 Subject: [PATCH] inline: rename "pathfields" to "item_fields" --- beetsplug/inline.py | 10 +++++++--- docs/changelog.rst | 4 +++- docs/plugins/inline.rst | 10 +++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/beetsplug/inline.py b/beetsplug/inline.py index 88628f900..9af015f73 100644 --- a/beetsplug/inline.py +++ b/beetsplug/inline.py @@ -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) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2c42d65b1..64c8890d3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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. diff --git a/docs/plugins/inline.rst b/docs/plugins/inline.rst index a98f52cd6..fddd2c974 100644 --- a/docs/plugins/inline.rst +++ b/docs/plugins/inline.rst @@ -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