From 69bac864abee684b6885cd201f1279d1121bf2ec Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Fri, 2 Nov 2018 08:00:00 +0000 Subject: [PATCH] Raise exception if template has invalid variables If the template string contains variables which aren't valid for whipper, raise ValueError exception listing all the included unrecognized variables. I've also corrected the example template configuration lines in the README. Fixes #279. --- README.md | 2 +- whipper/common/program.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7f2ff3..1c62f0e 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ read_offset = 6 ; drive read offset in positive/negative frames (no leading +) unknown = True output_directory = ~/My Music track_template = new/%%A/%%y - %%d/%%t - %%n ; note: the format char '%' must be represented '%%' -disc_template = %(track_template)s +disc_template = new/%%A/%%y - %%d/%%A - %%d # ... ``` diff --git a/whipper/common/program.py b/whipper/common/program.py index 78790b4..8401916 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -196,6 +196,10 @@ class Program: """ assert isinstance(outdir, unicode), "%r is not unicode" % outdir assert isinstance(template, unicode), "%r is not unicode" % template + matches = re.findall(r"%[^A,S,d,y,r,R,x,X]", template) + if '%' in template and matches: + raise ValueError('disc template string contains invalid ' + 'variable(s): {}.'.format(', '.join(matches))) v = {} v['A'] = 'Unknown Artist' v['d'] = mbdiscid # fallback for title