diff options
author | Pjotr Prins | 2016-10-03 09:23:57 +0000 |
---|---|---|
committer | Pjotr Prins | 2016-10-03 09:23:57 +0000 |
commit | 598fbead85b0ecb9127989a9c5a88a2d7bc91a5d (patch) | |
tree | 6257a4c529bdf946ea42e09c6a92b6ab9aeeeffa /wqflask/utility/tools.py | |
parent | 2acd8aa41580aaccc4119a6f504bdfb5e986e0c2 (diff) | |
download | genenetwork2-598fbead85b0ecb9127989a9c5a88a2d7bc91a5d.tar.gz |
Config: supporting JSON OVERRIDES
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r-- | wqflask/utility/tools.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 545c0427..23d6fb62 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -3,6 +3,7 @@ import os import sys +import json from wqflask import app @@ -10,6 +11,8 @@ from wqflask import app import logging logger = logging.getLogger(__name__ ) +OVERRIDES = {} + def get_setting(command_id,guess=None): """Resolve a setting from the environment or the global settings in app.config, with valid_path is a function checking whether the @@ -45,13 +48,15 @@ def get_setting(command_id,guess=None): logger.debug("Looking for "+command_id+"\n") command = value(os.environ.get(command_id)) if command is None or command == "": - # ---- Check whether setting exists in app - command = value(app.config.get(command_id)) + command = OVERRIDES.get(command_id) if command is None: - command = value(guess) - if command is None or command == "": - # print command - raise Exception(command_id+' setting unknown or faulty (update default_settings.py?).') + # ---- Check whether setting exists in app + command = value(app.config.get(command_id)) + if command is None: + command = value(guess) + 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 @@ -169,6 +174,7 @@ def show_settings(): log_level = getattr(logging, LOG_LEVEL.upper()) logging.basicConfig(level=log_level) + logger.info(OVERRIDES) logger.info(BLUE+"Mr. Mojo Risin 2"+ENDC) print "runserver.py: ****** Webserver configuration ******" keylist = app.config.keys() @@ -179,7 +185,9 @@ def show_settings(): except: print("%s: %s%s%s%s" % (k,GREEN,BOLD,app.config[k],ENDC)) + # Cached values +HOME = get_setting('HOME') WEBSERVER_MODE = get_setting('WEBSERVER_MODE') GN_SERVER_URL = get_setting('GN_SERVER_URL') SQL_URI = get_setting('SQL_URI') @@ -198,3 +206,18 @@ PYLMM_COMMAND = pylmm_command() GEMMA_COMMAND = gemma_command() PLINK_COMMAND = plink_command() TEMPDIR = tempdir() + +from six import string_types + +if os.environ.get('WQFLASK_OVERRIDES'): + jsonfn = get_setting('WQFLASK_OVERRIDES') + logger.error("WQFLASK_OVERRIDES: %s" % jsonfn) + with open(jsonfn) as data_file: + overrides = json.load(data_file) + for k in overrides: + cmd = overrides[k] + if isinstance(cmd, string_types): + OVERRIDES[k] = eval(cmd) + else: + OVERRIDES[k] = cmd + logger.debug(OVERRIDES) |