From c64c322c70ea4d30bf9d80b790a125efa277fb27 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 12 May 2015 21:45:14 +0000 Subject: More elaborate handling of finding pylmm --- wqflask/utility/tools.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'wqflask') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 3c972557..3eabd044 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -6,32 +6,46 @@ # 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(): +def get_setting(id,default,guess,get_valid_path): """ Resolve a setting from the environment or the global settings in app.config """ - pass - -def pylmm_command(default=None): - def get_valid_path(path): - if path and os.path.isfile(path+'/lmm.py'): - return path - else: - None - # ---- Check whether environment exists - path = get_valid_path(os.environ['PYLMM_PATH']) + path = get_valid_path(os.environ.get(id)) # ---- Check whether setting exists + setting = app.config.get(id) if not path: - path = get_valid_path(app.config.get('PYLMM_PATH')) + path = get_valid_path(setting) # ---- Check whether default exists if not path: path = get_valid_path(default) - home = get_valid_path(os.environ['HOME']+'/pylmm_gn2') + # ---- Guess directory if not path: - path = get_valid_path(home) + if not setting: + setting = guess + path = get_valid_path(guess) if not path: - raise Exception('PYLMM_PATH '+home+' unknown or faulty (add PYLMM_PATH to settings.py)') - pylmm_command = 'python '+path+'/lmm.py' + raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?)') + + 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 -- cgit v1.2.3