Fix template validation error
Commit 9c72ebccd3 introduced a bug: all template strings are validated against the disc template RegEx (which, for example, is wrong if we're testing the track template).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user