From 56c379f36dea4fb1e4069b71de61613a3710f4a4 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 29 Dec 2012 22:16:30 -0800 Subject: [PATCH] migrate path formats and replacements --- beets/ui/migrate.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/beets/ui/migrate.py b/beets/ui/migrate.py index 21b81ce0d..36eaedcdd 100644 --- a/beets/ui/migrate.py +++ b/beets/ui/migrate.py @@ -21,6 +21,7 @@ import codecs import yaml import logging import time +import itertools import beets from beets import util @@ -43,6 +44,11 @@ AUTO_KEYS = ('automatic', 'autofetch', 'autoembed', 'autoscrub') log = logging.getLogger('beets') +# An itertools recipe. +def grouper(n, iterable): + args = [iter(iterable)] * n + return itertools.izip_longest(*args) + def default_paths(): """Produces the appropriate default config and library database paths for the current system. On Unix, this is always in ~. On @@ -94,7 +100,7 @@ def flatten_config(config): for section in config.sections(): sec_dict = out[section] = confit.OrderedDict() for option in config.options(section): - sec_dict[option] = config.get(section, option) + sec_dict[option] = config.get(section, option, True) return out def transform_value(value): @@ -147,6 +153,15 @@ def transform_data(data): new_plugins = [PLUGIN_NAMES.get(p, p) for p in plugins] out['plugins'] = ' '.join(new_plugins) + elif key == 'replace': + # YAMLy representation for character replacements. + replacements = confit.OrderedDict() + for pat, repl in grouper(2, value.split()): + if repl == '': + repl = '' + replacements[pat] = repl + out['replace'] = replacements + else: out[key] = value @@ -158,6 +173,10 @@ def transform_data(data): # Standardized "auto" option. if key in AUTO_KEYS: key = 'auto' + + # Unnecessary : hack in queries. + if section == 'paths': + key = key.replace('_', ':') sec_out[key] = transform_value(value)