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:
JoeLametta
2018-11-04 08:00:00 +00:00
parent f0fcae872d
commit 4f5b684ec7
3 changed files with 17 additions and 4 deletions

View File

@@ -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