aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/tools.py
diff options
context:
space:
mode:
authorPjotr Prins2016-04-20 08:28:44 +0000
committerPjotr Prins2016-04-20 08:28:44 +0000
commitbeb6a9360ecc9edca19692e4081efc15292fb7d1 (patch)
treec736745b7bfac9eec844bbdbc582e44960e3d487 /wqflask/utility/tools.py
parent73ef712f3fd02df7ffa84a2b35ee5648f689d31b (diff)
downloadgenenetwork2-beb6a9360ecc9edca19692e4081efc15292fb7d1.tar.gz
[PATCH 018/100] Find external tools: refactored code to work with GNU Guix
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r--wqflask/utility/tools.py92
1 files changed, 43 insertions, 49 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index b8a41f60..0db195df 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -9,76 +9,70 @@ 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
+def get_setting(id,default,guess,find_path):
+ """Resolve a setting from the environment or the global settings in
+ app.config, with get_valid_path is a function checking whether the
+ path points to an expected directory an returns the full path e.g.
+
+ guess = os.environ.get('HOME')+'/pylmm'
+ get_setting('PYLMM_PATH',default,guess,get_valid_path)
+
+ first tries the environment variable in +id+, next gets the Flask
+ app setting for the same +id+, next tries the path passed in with
+ +default+ and finally does an educated +guess+.
+
+ In all, the environment overrides the others, next is the flask
+ setting, then the default and finally the guess (which is
+ $HOME/repo). A valid path is returned. If none is resolved an
+ exception is thrown.
+
+ Note that we do not use the system path. This is on purpose
+ because it will mess up controlled (reproducible) deployment. The
+ proper way is to either use the GNU Guix defaults as listed in
+ etc/default_settings.py or override them yourself by creating a
+ different settings.py file (or setting the environment).
+
"""
# ---- Check whether environment exists
- path = get_valid_path(os.environ.get(id))
+ path = find_path(os.environ.get(id))
# ---- Check whether setting exists
setting = app.config.get(id)
if not path:
- path = get_valid_path(setting)
+ path = find_path(setting)
# ---- Check whether default exists
if not path:
- path = get_valid_path(default)
+ path = find_path(default)
# ---- Guess directory
if not path:
+ guess = os.environ.get('HOME')+guess
if not setting:
setting = guess
- path = get_valid_path(guess)
+ path = find_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')
-
+ raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the path')
return path
-def pylmm_command(default=None):
- """
- Return the path to the repository and the python command to call
- """
- def get_valid_path(path):
+def find_command(command,id1,default,guess):
+ def find_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'):
+ sys.stderr.write("Trying "+id1+" in "+path+"\n")
+ binary = str.split(command)[0]
+ if path and os.path.isfile(path+'/'+binary):
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
-
-def plink_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 PLINK_PATH in "+path+"\n")
- if path and os.path.isfile(path+'/plink'):
- return path
- else:
- None
+ path = get_setting(id1,default,guess,find_path)
+ binary = path+'/'+command
+ sys.stderr.write("Found "+binary+"\n")
+ return path,binary
- guess = os.environ.get('HOME')+'/plink_gemma'
- path = get_setting('PLINK_PATH',default,guess,get_valid_path)
- plink_command = path+'/plink'
- return path,plink_command
+def pylmm_command(default=None):
+ return find_command('pylmm_gn2/lmm.py',"PYLMM_PATH",default,'/pylmm2')
def gemma_command(default=None):
- def get_valid_path(path):
- """Test for a valid repository"""
- if path:
- sys.stderr.write("Trying PLINK_PATH in "+path+"\n")
- if path and os.path.isfile(path+'/plink'):
- return path
- else:
- None
+ return find_command('gemma',"GEMMA_PATH",default,'/gemma')
- guess = os.environ.get('HOME')+'/plink'
- path = get_setting('PLINK_PATH',default,guess,get_valid_path)
- gemma_command = path+'/gemma'
- return path, gemma_command \ No newline at end of file
+def plink_command(default=None):
+ return find_command('plink2',"PLINK_PATH",default,'/plink')