aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility
diff options
context:
space:
mode:
authorpjotrp2016-02-23 07:46:43 +0000
committerPjotr Prins2016-04-20 08:53:05 +0000
commitae8834ac9c0f15f2c397bb6727b8a8079bf175eb (patch)
treebd7ae2748b1e1c1f3c98fce66f84cec849d9410c /wqflask/utility
parentfe69b32993ba48623be49404ae07c817a568a01a (diff)
downloadgenenetwork2-ae8834ac9c0f15f2c397bb6727b8a8079bf175eb.tar.gz
tools.py: add function locate_without_error
Diffstat (limited to 'wqflask/utility')
-rw-r--r--wqflask/utility/tools.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 624df179..af1ab353 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -79,6 +79,11 @@ def flat_files(subdir=None):
return valid_path(base)
def locate(name, subdir=None):
+ """
+ Locate a static flat file in the GENENETWORK_FILES environment.
+
+ This function throws an error when the file is not found.
+ """
base = get_setting("GENENETWORK_FILES")
if subdir:
base = base+"/"+subdir
@@ -89,7 +94,24 @@ def locate(name, subdir=None):
else:
raise IOError("Can not locate "+lookfor)
raise IOError("Can not locate "+name)
-
+
+def locate_without_error(name, subdir=None):
+ """
+ Locate a static flat file in the GENENETWORK_FILES environment.
+
+ This function does not throw an error when the file is not found
+ but returns None.
+ """
+ base = get_setting("GENENETWORK_FILES")
+ if subdir:
+ base = base+"/"+subdir
+ if valid_path(base):
+ lookfor = base + "/" + name
+ if valid_path(lookfor):
+ return lookfor
+ sys.stderr.write("WARNING: file "+name+" not found\n")
+ return None
+
def tempdir():
return valid_path(get_setting("TEMPDIR","/tmp"))