From 1107259dc258d0cfcb447519cc36e59e78facdef Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 2 Oct 2016 11:52:47 +0000 Subject: Errors: added time stamps in UTC --- wqflask/utility/logger.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index ddc0ea82..b873e16f 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -31,6 +31,7 @@ import string from inspect import isfunction from pprint import pformat as pf from inspect import stack +import datetime from utility.tools import LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_SQL, LOG_FORMAT @@ -66,7 +67,10 @@ LOG_LEVEL_DEBUG (NYI). def error(self,*args): """Call logging.error for multiple args""" - self.collect(self.logger.error,*args) + now = datetime.datetime.utcnow() + time_str = now.strftime('%H:%M:%S UTC %Y%m%d') + l = [time_str]+list(args) + self.collect(self.logger.error,*l) def infof(self,*args): """Call logging.info for multiple args lazily""" -- cgit v1.2.3 From 2acd8aa41580aaccc4119a6f504bdfb5e986e0c2 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 3 Oct 2016 08:29:30 +0000 Subject: Debug: sanitize some output --- wqflask/base/webqtlCaseData.py | 2 -- wqflask/runserver.py | 1 - wqflask/utility/tools.py | 9 ++++----- wqflask/wqflask/__init__.py | 8 ++------ 4 files changed, 6 insertions(+), 14 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/base/webqtlCaseData.py b/wqflask/base/webqtlCaseData.py index 8df9939e..2f88f778 100644 --- a/wqflask/base/webqtlCaseData.py +++ b/wqflask/base/webqtlCaseData.py @@ -16,8 +16,6 @@ # Contact Drs. Robert W. Williams and Xiaodong Zhou (2010) # at rwilliams@uthsc.edu and xzhou15@uthsc.edu # -# -# # This module is used by GeneNetwork project (www.genenetwork.org) # # Created by GeneNetwork Core Team 2010/08/10 diff --git a/wqflask/runserver.py b/wqflask/runserver.py index 5a8766b0..0342b7ad 100644 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -16,7 +16,6 @@ GREEN = '\033[92m' BOLD = '\033[1m' ENDC = '\033[0m' - import os app.config['SECRET_KEY'] = os.urandom(24) diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 22779739..545c0427 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -50,7 +50,7 @@ def get_setting(command_id,guess=None): if command is None: command = value(guess) if command is None or command == "": - print command + # print command raise Exception(command_id+' setting unknown or faulty (update default_settings.py?).') logger.debug("Set "+command_id+"="+str(command)) return command @@ -170,15 +170,14 @@ def show_settings(): logging.basicConfig(level=log_level) logger.info(BLUE+"Mr. Mojo Risin 2"+ENDC) - print "runserver.py: ****** The webserver has the following configuration ******" + print "runserver.py: ****** Webserver 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)) + 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)) - + print("%s: %s%s%s%s" % (k,GREEN,BOLD,app.config[k],ENDC)) # Cached values WEBSERVER_MODE = get_setting('WEBSERVER_MODE') diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index af271d02..602246d9 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -8,17 +8,13 @@ from utility import formatting import logging logger = logging.getLogger(__name__ ) -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.WARN) app = Flask(__name__) app.config.from_object('cfg.default_settings') # Get the defaults from cfg.default_settings app.config.from_envvar('WQFLASK_SETTINGS') # See http://flask.pocoo.org/docs/config/#configuring-from-files - -logger.debug("System path is") -logger.debug(sys.path) -logger.debug("App.config is") -logger.debug(app.config) +# Note we also use WQFLASK_OVERRIDES app.jinja_env.globals.update( undefined = jinja2.StrictUndefined, -- cgit v1.2.3 From 598fbead85b0ecb9127989a9c5a88a2d7bc91a5d Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 3 Oct 2016 09:23:57 +0000 Subject: Config: supporting JSON OVERRIDES --- bin/genenetwork2 | 2 +- wqflask/utility/tools.py | 35 +++++++++++++++++++++++++++++------ wqflask/wqflask/__init__.py | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'wqflask/utility') diff --git a/bin/genenetwork2 b/bin/genenetwork2 index 872e9326..30a4dc95 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -56,7 +56,7 @@ if [ -z $TEMPDIR ]; then fi # Now handle command parameter -c -if [ $1 = '-c' ] ; then +if [ "$1" = '-c' ] ; then cd $GN2_BASE_PATH/wqflask cmd=${2#wqflask/} echo PYTHONPATH=$PYTHONPATH 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) diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index 602246d9..2188ce17 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -8,7 +8,7 @@ from utility import formatting import logging logger = logging.getLogger(__name__ ) -logging.basicConfig(level=logging.WARN) +logging.basicConfig(level=logging.INFO) app = Flask(__name__) -- cgit v1.2.3 From ff48bdbce4b4f5cb4c561b06268fd91d8fe546a4 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 5 Oct 2016 06:55:50 +0000 Subject: print statements should be logger --- wqflask/utility/helper_functions.py | 12 +++++++----- wqflask/wqflask/marker_regression/marker_regression.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py index 149ee553..377f6b26 100644 --- a/wqflask/utility/helper_functions.py +++ b/wqflask/utility/helper_functions.py @@ -5,19 +5,21 @@ from base import data_set from base.species import TheSpecies from wqflask import user_manager +import logging +logger = logging.getLogger(__name__ ) def get_species_dataset_trait(self, start_vars): #assert type(read_genotype) == type(bool()), "Expecting boolean value for read_genotype" self.dataset = data_set.create_dataset(start_vars['dataset']) - print("After creating dataset") + logger.debug("After creating dataset") self.species = TheSpecies(dataset=self.dataset) - print("After creating species") + logger.debug("After creating species") self.this_trait = GeneralTrait(dataset=self.dataset, name=start_vars['trait_id'], cellid=None, get_qtl_info=True) - print("After creating trait") + logger.debug("After creating trait") #if read_genotype: #self.dataset.group.read_genotype_file() @@ -27,7 +29,7 @@ def get_species_dataset_trait(self, start_vars): def get_trait_db_obs(self, trait_db_list): if isinstance(trait_db_list, basestring): trait_db_list = trait_db_list.split(",") - + self.trait_list = [] for trait in trait_db_list: data, _separator, hmac = trait.rpartition(':') @@ -38,4 +40,4 @@ def get_trait_db_obs(self, trait_db_list): trait_ob = GeneralTrait(dataset=dataset_ob, name=trait_name, cellid=None) - self.trait_list.append((trait_ob, dataset_ob)) \ No newline at end of file + self.trait_list.append((trait_ob, dataset_ob)) diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index f28407b3..324f128c 100644 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -814,7 +814,7 @@ class MarkerRegression(object): timestamp = datetime.datetime.now().isoformat(), ) - print("After creating params") + logger.debug("After creating params") json_params = json.dumps(params) Redis.set(key, json_params) -- cgit v1.2.3