aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r--wqflask/utility/tools.py86
1 files changed, 70 insertions, 16 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 11441d7a..bb8241f5 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -5,14 +5,18 @@ import os
import sys
from wqflask import app
+# Use the standard logger here to avoid a circular dependency
+import logging
+logger = logging.getLogger(__name__ )
+
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
+ app.config, with valid_path is a function checking whether the
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',guess)
+ valid_path(get_setting('PYLMM_PATH',guess))
first tries the environment variable in +id+, next gets the Flask
app setting for the same +id+ and finally does an educated
@@ -31,23 +35,39 @@ def get_setting(command_id,guess=None):
"""
def value(command):
if command:
- sys.stderr.write("Found path "+command+"\n")
+ # sys.stderr.write("Found "+command+"\n")
return command
else:
return None
# ---- Check whether environment exists
- sys.stderr.write("Looking for "+command_id+"\n")
+ logger.debug("Looking for "+command_id+"\n")
command = value(os.environ.get(command_id))
- if not command:
+ if command is None or command == "":
# ---- Check whether setting exists in app
command = value(app.config.get(command_id))
- if not command:
+ if command is None:
command = value(guess)
- if not command:
- raise Exception(command_id+' path unknown or faulty (update settings.py?). '+command_id+' should point to the path')
+ if command is None or command == "":
+ print command
+ raise Exception(command_id+' setting unknown or faulty (update default_settings.py?).')
+ logger.debug("Set "+command_id+"="+str(command))
return command
+def get_setting_bool(id):
+ v = get_setting(id)
+ if v not in [0,False,'False','FALSE',None]:
+ return True
+ return False
+
+def get_setting_int(id):
+ v = get_setting(id)
+ if isinstance(v, str):
+ return int(v)
+ if v is None:
+ return 0
+ return v
+
def valid_bin(bin):
if os.path.islink(bin) or valid_file(bin):
return bin
@@ -100,7 +120,7 @@ def locate(name, subdir=None):
if valid_path(base):
lookfor = base + "/" + name
if valid_file(lookfor):
- print("Found: file "+lookfor+"\n")
+ logger.info("Found: file "+lookfor+"\n")
return lookfor
else:
raise Exception("Can not locate "+lookfor)
@@ -120,18 +140,52 @@ def locate_ignore_error(name, subdir=None):
if valid_path(base):
lookfor = base + "/" + name
if valid_file(lookfor):
- print("Found: file "+name+"\n")
+ logger.debug("Found: file "+name+"\n")
return lookfor
- sys.stderr.write("WARNING: file "+name+" not found\n")
+ logger.info("WARNING: file "+name+" not found\n")
return None
def tempdir():
return valid_path(get_setting("TEMPDIR","/tmp"))
+BLUE = '\033[94m'
+GREEN = '\033[92m'
+BOLD = '\033[1m'
+ENDC = '\033[0m'
+
+def show_settings():
+ from utility.tools import LOG_LEVEL
+
+ print("Set global log level to "+BLUE+LOG_LEVEL+ENDC)
+ log_level = getattr(logging, LOG_LEVEL.upper())
+ logging.basicConfig(level=log_level)
+
+ logger.info(BLUE+"Mr. Mojo Risin 2"+ENDC)
+ print "runserver.py: ****** The webserver has the following configuration ******"
+ keylist = app.config.keys()
+ keylist.sort()
+ for k in keylist:
+ try:
+ print("%s %s%s%s%s" % (k,BLUE,BOLD,get_setting(k),ENDC))
+ except:
+ print("%s %s%s%s%s" % (k,GREEN,BOLD,app.config[k],ENDC))
+
# Cached values
-PYLMM_COMMAND = pylmm_command()
-GEMMA_COMMAND = gemma_command()
-PLINK_COMMAND = plink_command()
-FLAT_FILES = flat_files()
-TEMPDIR = tempdir()
+WEBSERVER_MODE = get_setting('WEBSERVER_MODE')
+GN_SERVER_URL = get_setting('GN_SERVER_URL')
+SQL_URI = get_setting('SQL_URI')
+LOG_LEVEL = get_setting('LOG_LEVEL')
+LOG_LEVEL_DEBUG = get_setting_int('LOG_LEVEL_DEBUG')
+LOG_SQL = get_setting_bool('LOG_SQL')
+LOG_SQLALCHEMY = get_setting_bool('LOG_SQLALCHEMY')
+LOG_BENCH = get_setting_bool('LOG_BENCH')
+LOG_FORMAT = "%(message)s" # not yet in use
+USE_REDIS = get_setting_bool('USE_REDIS')
+USE_GN_SERVER = get_setting_bool('USE_GN_SERVER')
+
+PYLMM_COMMAND = pylmm_command()
+GEMMA_COMMAND = gemma_command()
+PLINK_COMMAND = plink_command()
+FLAT_FILES = flat_files()
+TEMPDIR = tempdir()