From 358f0cd5e8f3e23ca059c3fd5c1c5739faaeb425 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 3 Oct 2016 08:06:25 +0000 Subject: Handle JSON override files in startup script --- bin/genenetwork2 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'bin') diff --git a/bin/genenetwork2 b/bin/genenetwork2 index d926d6a1..872e9326 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -1,14 +1,19 @@ #! /bin/bash # -# This will run the GN2 server (with default settings if none supplied). Pass in -# your own settings file, e.g. +# This will run the GN2 server (with default settings if none +# supplied). Pass in your own settings file, e.g. # # ./bin/genenetwork2 ~/my_settings.py # +# But better is to retain the defaults and override them with +# JSON file (see the deploy docs). +# +# ./bin/genenetwork2 ~/my_overrides.json +# # To run a maintenance script with settings (instead of the webserver) add that with # a -c switch, e.g. # -# ./bin/genenetwork2 ~/my_settings.py -c ./wqflask/maintenance/gen_select_dataset.py +# ./bin/genenetwork2 ~/my_overrides.json -c ./wqflask/maintenance/gen_select_dataset.py # # Environment settings can be used to preconfigure as well as a # settings.py file. @@ -23,10 +28,11 @@ if [ -d $GN2_GUIX_PATH ]; then fi echo $GN2_BASE_PATH -# Handle settings parameter +# Handle settings parameter (can be .py or .json) settings=$1 -if [ -z $settings ]; then - # get default +ext="${settings##*.}" +if [ -z "$settings" -o "$ext" = "json" -o "$ext" = "JSON" ]; then + overrides=$settings settings=$GN2_BASE_PATH/etc/default_settings.py else shift @@ -35,7 +41,11 @@ if [ ! -e $settings ]; then echo "ERROR: can not locate settings file - pass it in the command line" exit 1 fi -export WQFLASK_SETTINGS=$settings +export WQFLASK_SETTINGS=$settings # Python +export WQFLASK_OVERRIDES=$overrides # JSON + +echo WQFLASK_SETTINGS=$settings +echo WQFLASK_OVERRIDES=$overrides # We may change this one: export PYTHONPATH=$GN2_BASE_PATH/wqflask:$PYTHONPATH -- 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 'bin') 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 3df145309159efd18dadc537ac7eebafef5b4595 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 3 Oct 2016 10:40:21 +0000 Subject: Use of GN2_PROFILE --- bin/genenetwork2 | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/genenetwork2 b/bin/genenetwork2 index 30a4dc95..889401fd 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -17,29 +17,33 @@ # # Environment settings can be used to preconfigure as well as a # settings.py file. +# +# GN2_BASE_PATH is base directory of wqflask source code +# SCRIPT=$(readlink -f "$0") -GN2_BASE_PATH=$(dirname $(dirname "$SCRIPT")) +GN2_BASE_DIR=$(dirname $(dirname "$SCRIPT")) + +echo GN2_BASE_DIR=$GN2_BASE_DIR -GN2_GUIX_PATH=$GN2_BASE_PATH/lib/python2.7/site-packages/genenetwork2-2.0-py2.7.egg -if [ -d $GN2_GUIX_PATH ]; then - echo GN2 is running from GUIX - GN2_BASE_PATH=$GN2_GUIX_PATH -fi -echo $GN2_BASE_PATH # Handle settings parameter (can be .py or .json) settings=$1 ext="${settings##*.}" if [ -z "$settings" -o "$ext" = "json" -o "$ext" = "JSON" ]; then overrides=$settings - settings=$GN2_BASE_PATH/etc/default_settings.py + settings=$GN2_BASE_DIR/etc/default_settings.py else shift fi if [ ! -e $settings ]; then - echo "ERROR: can not locate settings file - pass it in the command line" - exit 1 + GUIX_ETC=$GN2_BASE_DIR/lib/python2.7/site-packages/genenetwork2-2.0-py2.7.egg + if [ -d $GUIX_ETC ]; then + echo INFO: GN2 is actually running from GNU Guix + else + echo "ERROR: can not locate settings file - pass it in the command line" + exit 1 + fi fi export WQFLASK_SETTINGS=$settings # Python export WQFLASK_OVERRIDES=$overrides # JSON @@ -47,17 +51,43 @@ export WQFLASK_OVERRIDES=$overrides # JSON echo WQFLASK_SETTINGS=$settings echo WQFLASK_OVERRIDES=$overrides +# ---- Checks and balances +if [ -z $GUIX_ETC ]; then + if [ -z $GN2_PROFILE ] ; then + echo "WARNING: GN2_PROFILE has not been set - I hope you know what you are doing" + else + export PYTHONPATH=$GN2_PROFILE/lib/python2.7/site-packages + export R_LIBS_SITE=$GN2_PROFILE/site-library + export GUIX_GTK3_PATH="$GN2_PROFILE/lib/gtk-3.0" + export GI_TYPELIB_PATH="$GN2_PROFILE/lib/girepository-1.0" + export XDG_DATA_DIRS="$GN2_PROFILE/share" + export GIO_EXTRA_MODULES="$GN2_PROFILE/lib/gio/modules" + fi + if [ -z $PYTHONPATH ] ; then + echo "WARNING PYTHONPATH has not been set" + fi + if [ ! -d $R_LIBS_SITE ] ; then + echo "ERROR: R_LIBS_SITE has not been set correctly (we only allow one path)" + echo "Paste in the output of, for example," + echo "guix package -p /usr/local/guix-profiles/gn2-staging --search-paths" + exit 1 + fi +fi + # We may change this one: -export PYTHONPATH=$GN2_BASE_PATH/wqflask:$PYTHONPATH +export PYTHONPATH=$GN2_BASE_DIR/wqflask:$PYTHONPATH # TEMPDIR defaults to /tmp if nothing else if [ -z $TEMPDIR ]; then TEMPDIR="/tmp" fi +set|grep $GN2_PROFILE +set|grep TEMPDIR + # Now handle command parameter -c if [ "$1" = '-c' ] ; then - cd $GN2_BASE_PATH/wqflask + cd $GN2_BASE_DIR/wqflask cmd=${2#wqflask/} echo PYTHONPATH=$PYTHONPATH echo RUNNING COMMAND $cmd @@ -71,6 +101,6 @@ dbfilename gn2.rdb " | redis-server - & # Start the flask server running GN2 -cd $GN2_BASE_PATH/wqflask +cd $GN2_BASE_DIR/wqflask echo "Starting with $settings" /usr/bin/env python runserver.py -- cgit v1.2.3 From 74ae90740b4d0b305199474359056fe4123224b1 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 5 Oct 2016 06:52:34 +0000 Subject: Testing: show --all option --- bin/test-website | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bin') diff --git a/bin/test-website b/bin/test-website index b693bd60..c9a72a5e 100755 --- a/bin/test-website +++ b/bin/test-website @@ -15,6 +15,10 @@ If you are using the small deployment database you can use ./bin/test-website --skip -n +To run all tests + + ./bin/test-website --all + To run individual tests on localhost you can do ruby -Itest -Itest/lib test/lib/mapping.rb --name="/Mapping/" -- cgit v1.2.3