diff options
author | zsloan | 2015-05-13 11:44:49 -0500 |
---|---|---|
committer | zsloan | 2015-05-13 11:44:49 -0500 |
commit | 8fa315467f70a4b14e40ed2f5d4adce15ef24bc6 (patch) | |
tree | 992d5bef1f93d9b035bded4bd224cdbf617043cb /wqflask/utility/tools.py | |
parent | 8e8e14bbd6ae680c27f1db1837c09c1aa2cc642b (diff) | |
parent | 6d14bf787c53ba3701b8be91202c1c880309ca59 (diff) | |
download | genenetwork2-8fa315467f70a4b14e40ed2f5d4adce15ef24bc6.tar.gz |
Merge pull request #39 from pjotrp/master
Refactoring finding tools such as pylmm
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r-- | wqflask/utility/tools.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py new file mode 100644 index 00000000..1a5c19d9 --- /dev/null +++ b/wqflask/utility/tools.py @@ -0,0 +1,51 @@ +# Tools/paths finder resolves external paths from settings and/or environment +# variables +# +# Currently supported: +# +# PYLMM_PATH finds the root of the git repository of the pylmm_gn2 tool + +import os +import sys +from wqflask import app + +def get_setting(id,default,guess,get_valid_path): + """ + Resolve a setting from the environment or the global settings in app.config + """ + # ---- Check whether environment exists + path = get_valid_path(os.environ.get(id)) + # ---- Check whether setting exists + setting = app.config.get(id) + if not path: + path = get_valid_path(setting) + # ---- Check whether default exists + if not path: + path = get_valid_path(default) + # ---- Guess directory + if not path: + if not setting: + setting = guess + path = get_valid_path(guess) + if not path: + raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the root of the git repository') + + return path + +def pylmm_command(default=None): + """ + Return the path to the repository and the python command to call + """ + def get_valid_path(path): + """Test for a valid repository""" + if path: + sys.stderr.write("Trying PYLMM_PATH in "+path+"\n") + if path and os.path.isfile(path+'/pylmm_gn2/lmm.py'): + return path + else: + None + + guess = os.environ.get('HOME')+'/pylmm_gn2' + path = get_setting('PYLMM_PATH',default,guess,get_valid_path) + pylmm_command = 'python '+path+'/pylmm_gn2/lmm.py' + return path,pylmm_command |