From 81e7eb42156a21e17d81c4a71d1dfee4f0fbd52f Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Oct 2014 13:42:47 -0400 Subject: [PATCH] 4042: Subst will raise exceptions if files/directories don't exist. --- crunch_scripts/crunchutil/subst.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crunch_scripts/crunchutil/subst.py b/crunch_scripts/crunchutil/subst.py index ff3486354f..b7336fa332 100644 --- a/crunch_scripts/crunchutil/subst.py +++ b/crunch_scripts/crunchutil/subst.py @@ -1,5 +1,6 @@ import os import glob +import stat class SubstitutionError(Exception): pass @@ -35,13 +36,23 @@ def search(c): return None def sub_file(v): - return os.path.join(os.environ['TASK_KEEPMOUNT'], v) + path = os.path.join(os.environ['TASK_KEEPMOUNT'], v) + st = os.stat(path) + if st and stat.S_ISREG(st.st_mode): + return path + else: + raise SubstitutionError("$(file {}) is not accessable or is not a regular file".format(path)) def sub_dir(v): d = os.path.dirname(v) if d == '': d = v - return os.path.join(os.environ['TASK_KEEPMOUNT'], d) + path = os.path.join(os.environ['TASK_KEEPMOUNT'], d) + st = os.stat(path) + if st and stat.S_ISDIR(st.st_mode): + return path + else: + raise SubstitutionError("$(dir {}) is not accessable or is not a directory".format(path)) def sub_basename(v): return os.path.splitext(os.path.basename(v))[0] @@ -49,7 +60,7 @@ def sub_basename(v): def sub_glob(v): l = glob.glob(v) if len(l) == 0: - raise SubstitutionError("$(glob): No match on '%s'" % v) + raise SubstitutionError("$(glob {}) no match fonud".format(v)) else: return l[0] -- 2.30.2