4 class SubstitutionError(Exception):
18 elif state == DEFAULT:
34 raise SubstitutionError("Substitution error, mismatched parentheses {}".format(c))
38 return os.path.join(os.environ['TASK_KEEPMOUNT'], v)
41 d = os.path.dirname(v)
44 return os.path.join(os.environ['TASK_KEEPMOUNT'], d)
47 return os.path.splitext(os.path.basename(v))[0]
52 raise SubstitutionError("$(glob): No match on '%s'" % v)
56 default_subs = {"file ": sub_file,
58 "basename ": sub_basename,
61 def do_substitution(p, c, subs=default_subs):
67 v = do_substitution(p, c[m[0]+2 : m[1]])
71 r = subs[sub](v[len(sub):])
78 raise SubstitutionError("Unknown variable or function '%s' while performing substitution on '%s'" % (v, c))
80 raise SubstitutionError("Substitution for '%s' is null while performing substitution on '%s'" % (v, c))
81 if not isinstance(r, basestring):
82 raise SubstitutionError("Substitution for '%s' must be a string while performing substitution on '%s'" % (v, c))
84 c = c[:m[0]] + r + c[m[1]+1:]