aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/tools.py
diff options
context:
space:
mode:
authorPjotr Prins2016-04-20 08:37:55 +0000
committerPjotr Prins2016-04-20 08:37:55 +0000
commitaf7d0bca229f3ebaa80a16d1ce3a2bf1a8abd5df (patch)
tree61dfc53eed849cb0f136066de0256f1cfb3beb5b /wqflask/utility/tools.py
parentc76299fa981add7b8cf56126c8d7ffeb9a6c4034 (diff)
downloadgenenetwork2-af7d0bca229f3ebaa80a16d1ce3a2bf1a8abd5df.tar.gz
[PATCH 023/100] WIP fixing all paths
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r--wqflask/utility/tools.py82
1 files changed, 36 insertions, 46 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 0db195df..c3c9b292 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -9,22 +9,22 @@ import os
import sys
from wqflask import app
-def get_setting(id,default,guess,find_path):
+def get_setting(command_id,guess=None):
"""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.
+ path points to an expected directory and returns the full path to
+ the binary command
guess = os.environ.get('HOME')+'/pylmm'
- get_setting('PYLMM_PATH',default,guess,get_valid_path)
+ get_setting('PYLMM_PATH',guess)
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+.
+ app setting for the same +id+ 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.
+ setting, then the guess. A valid path to the binary command 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
@@ -33,46 +33,36 @@ def get_setting(id,default,guess,find_path):
different settings.py file (or setting the environment).
"""
- # ---- Check whether environment exists
- path = find_path(os.environ.get(id))
- # ---- Check whether setting exists
- setting = app.config.get(id)
- if not path:
- path = find_path(setting)
- # ---- Check whether default exists
- if not path:
- path = find_path(default)
- # ---- Guess directory
- if not path:
- guess = os.environ.get('HOME')+guess
- if not setting:
- setting = guess
- path = find_path(guess)
- if not path:
- raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the path')
- return path
-
-def find_command(command,id1,default,guess):
- def find_path(path):
- """Test for a valid repository"""
- if path:
- sys.stderr.write("Trying "+id1+" in "+path+"\n")
- binary = str.split(command)[0]
- if path and os.path.isfile(path+'/'+binary):
- return path
+ def valid(command):
+ if command:
+ sys.stderr.write("Found value "+command+"\n")
+ return command
else:
- None
+ return None
+
+ # ---- Check whether environment exists
+ sys.stderr.write("Looking for "+command_id+"\n")
+ command = valid(os.environ.get(command_id))
+ if not command:
+ # ---- Check whether setting exists in app
+ command = valid(app.config.get(command_id))
+ if not command:
+ command = valid(guess)
+ if not command:
+ raise Exception(command_id+' path unknown or faulty (update settings.py?). '+command_id+' should point to the path')
+ return command
- path = get_setting(id1,default,guess,find_path)
- binary = path+'/'+command
- sys.stderr.write("Found "+binary+"\n")
- return path,binary
+def pylmm_command(guess=None):
+ return get_setting("PYLMM_RUN",guess)
-def pylmm_command(default=None):
- return find_command('pylmm_gn2/lmm.py',"PYLMM_PATH",default,'/pylmm2')
+def gemma_command(guess=None):
+ return get_setting("GEMMA_RUN",guess)
-def gemma_command(default=None):
- return find_command('gemma',"GEMMA_PATH",default,'/gemma')
+def plink_command(guess=None):
+ return get_setting("PLINK_RUN",guess)
-def plink_command(default=None):
- return find_command('plink2',"PLINK_PATH",default,'/plink')
+def flat_files(subdir=None):
+ base = get_setting("GENENETWORK_FILES")
+ if subdir:
+ return base+"/"+subdir
+ return base