diff --git a/whipper/command/cd.py b/whipper/command/cd.py index aa7d11b..1ba0658 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -28,6 +28,7 @@ from whipper.command.basecommand import BaseCommand from whipper.common import ( accurip, config, drive, program, task ) +from whipper.common.common import validate_template from whipper.program import cdrdao, cdparanoia, utils from whipper.result import result @@ -285,7 +286,9 @@ Log files will log the path to tracks relative to this directory. self.options.track_template = self.options.track_template.decode( 'utf-8') + validate_template(self.options.track_template, 'track') self.options.disc_template = self.options.disc_template.decode('utf-8') + validate_template(self.options.disc_template, 'disc') if self.options.offset is None: raise ValueError("Drive offset is unconfigured.\n" diff --git a/whipper/common/common.py b/whipper/common/common.py index 9bd20de..39c0913 100644 --- a/whipper/common/common.py +++ b/whipper/common/common.py @@ -22,6 +22,7 @@ import os import os.path import math +import re import subprocess import unicodedata @@ -280,6 +281,19 @@ def getRelativePath(targetPath, collectionPath): return os.path.join(rel, os.path.basename(targetPath)) +def validate_template(template, kind): + """ + Raise exception if disc/track template includes invalid variables + """ + if kind == 'disc': + matches = re.findall(r'%[^A,R,S,X,d,r,x,y]', template) + elif kind == 'track': + matches = re.findall(r'%[^A,R,S,X,a,d,n,r,s,t,x,y]', template) + if '%' in template and matches: + raise ValueError(kind + ' template string contains invalid ' + 'variable(s): {}'.format(', '.join(matches))) + + class VersionGetter(object): """ I get the version of a program by looking for it in command output diff --git a/whipper/common/program.py b/whipper/common/program.py index 5f8b400..7469b09 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -196,10 +196,6 @@ 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