From 6c0f35e56e8d26a47d210b12c171bb050d1ab150 Mon Sep 17 00:00:00 2001 From: pjotrp Date: Tue, 23 Feb 2016 09:27:57 +0000 Subject: Fine tuning file locating --- wqflask/utility/tools.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'wqflask/utility/tools.py') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index af1ab353..dd40be99 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -54,10 +54,15 @@ def get_setting(command_id,guess=None): return command def valid_bin(bin): - if os.path.islink(bin) or os.path.isfile(bin): + if os.path.islink(bin) or valid_file(bin): return bin return None +def valid_file(fn): + if os.path.isfile(fn): + return fn + return None + def valid_path(dir): if os.path.isdir(dir): return dir @@ -89,11 +94,12 @@ def locate(name, subdir=None): base = base+"/"+subdir if valid_path(base): lookfor = base + "/" + name - if valid_path(lookfor): + if valid_file(lookfor): return lookfor else: raise IOError("Can not locate "+lookfor) - raise IOError("Can not locate "+name) + if subdir: sys.stderr.write(subdir) + raise IOError("Can not locate "+name+" in "+base) def locate_without_error(name, subdir=None): """ @@ -107,7 +113,7 @@ def locate_without_error(name, subdir=None): base = base+"/"+subdir if valid_path(base): lookfor = base + "/" + name - if valid_path(lookfor): + if valid_file(lookfor): return lookfor sys.stderr.write("WARNING: file "+name+" not found\n") return None -- cgit v1.2.3