From 74f14a7aeb6d08fe24eef74eb75591aa17e81a10 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 31 Jan 2012 18:52:27 -0800 Subject: [PATCH] fix plugin errors with missing sections --- beetsplug/inline.py | 11 ++++++----- beetsplug/rewrite.py | 2 ++ docs/changelog.rst | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/beetsplug/inline.py b/beetsplug/inline.py index ee5b38e08..4e4dfa00c 100644 --- a/beetsplug/inline.py +++ b/beetsplug/inline.py @@ -59,8 +59,9 @@ class InlinePlugin(BeetsPlugin): cls = type(self) # Add field expressions. - for key, value in config.items('pathfields', True): - log.debug(u'adding template field %s' % key) - func = compile_expr(value) - if func is not None: - cls.template_fields[key] = func + if config.has_section('pathfields'): + for key, value in config.items('pathfields', True): + log.debug(u'adding template field %s' % key) + func = compile_expr(value) + if func is not None: + cls.template_fields[key] = func diff --git a/beetsplug/rewrite.py b/beetsplug/rewrite.py index 078b00786..609999749 100644 --- a/beetsplug/rewrite.py +++ b/beetsplug/rewrite.py @@ -48,6 +48,8 @@ class RewritePlugin(BeetsPlugin): # Gather all the rewrite rules for each field. rules = defaultdict(list) + if not config.has_section('rewrite'): + return for key, value in config.items('rewrite', True): try: fieldname, pattern = key.split(None, 1) diff --git a/docs/changelog.rst b/docs/changelog.rst index 97a8a44d7..ca24bb34e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -32,6 +32,8 @@ Changelog recording associated with a fingerprint. * Fix a crash when an autotagging with an artist or album containing "AND" or "OR" (upper case). +* Fix an error in the ``rewrite`` and ``inline`` plugins when the corresponding + config sections did not exist. 1.0b12 (January 16, 2012) -------------------------