blob: 6e35f00a439881a6a8bd1a77fdf0a86e3353e015 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# 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
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
guess = os.environ.get('HOME')+'/plink'
path = get_setting('PLINK_PATH',default,guess,get_valid_path)
plink_command = path+'/plink'
return path,plink_command
|