about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rwxr-xr-xbin/genenetwork282
-rw-r--r--wqflask/base/webqtlCaseData.py2
-rw-r--r--wqflask/runserver.py19
-rw-r--r--wqflask/utility/tools.py40
-rw-r--r--wqflask/wqflask/__init__.py6
6 files changed, 105 insertions, 46 deletions
diff --git a/VERSION b/VERSION
index cd5ac039..144b089a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0
+2.10-pre1
diff --git a/bin/genenetwork2 b/bin/genenetwork2
index d926d6a1..889401fd 100755
--- a/bin/genenetwork2
+++ b/bin/genenetwork2
@@ -1,53 +1,93 @@
 #! /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.
+#
+# 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"))
 
-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
+echo GN2_BASE_DIR=$GN2_BASE_DIR
 
-# Handle settings parameter
+
+# Handle settings parameter (can be .py or .json)
 settings=$1
-if [ -z $settings ]; then
-    # get default
-    settings=$GN2_BASE_PATH/etc/default_settings.py
+ext="${settings##*.}"
+if [ -z "$settings" -o "$ext" = "json" -o "$ext" = "JSON" ]; then
+    overrides=$settings
+    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
+
+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
-export WQFLASK_SETTINGS=$settings
 
 # 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
+if [ "$1" = '-c' ] ; then
+    cd $GN2_BASE_DIR/wqflask
     cmd=${2#wqflask/}
     echo PYTHONPATH=$PYTHONPATH
     echo RUNNING COMMAND $cmd
@@ -61,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
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 12ec904e..0342b7ad 100644
--- a/wqflask/runserver.py
+++ b/wqflask/runserver.py
@@ -16,34 +16,37 @@ GREEN = '\033[92m'
 BOLD  = '\033[1m'
 ENDC  = '\033[0m'
 
-logger.info("GN2 is running. Visit %shttp://localhost:5003/%s" % (BLUE,ENDC))
-
 import os
 app.config['SECRET_KEY'] = os.urandom(24)
 
-from utility.tools import WEBSERVER_MODE
+from utility.tools import WEBSERVER_MODE,get_setting_int
+
+port = get_setting_int("SERVER_PORT")
+
+logger.info("GN2 is running. Visit %shttp://localhost:%s/%s" % (BLUE,port,ENDC))
 
 werkzeug_logger = logging.getLogger('werkzeug')
 
 if WEBSERVER_MODE == 'DEBUG':
     app.run(host='0.0.0.0',
-            port=app.config['SERVER_PORT'],
+            port=port,
             debug=True,
-            use_debugger=True,
+            use_debugger=False,
             threaded=False,
+            processes=0,
             use_reloader=True)
 elif WEBSERVER_MODE == 'DEV':
     werkzeug_logger.setLevel(logging.WARNING)
     app.run(host='0.0.0.0',
-            port=app.config['SERVER_PORT'],
+            port=port,
             debug=False,
             use_debugger=False,
             threaded=False,
             processes=0,
             use_reloader=True)
-else: #production mode
+else: # staging/production modes
     app.run(host='0.0.0.0',
-            port=app.config['SERVER_PORT'],
+            port=port,
             debug=False,
             use_debugger=False,
             threaded=True,
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 22779739..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,18 +174,20 @@ 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: ****** 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
+HOME               = get_setting('HOME')
 WEBSERVER_MODE     = get_setting('WEBSERVER_MODE')
 GN_SERVER_URL      = get_setting('GN_SERVER_URL')
 SQL_URI            = get_setting('SQL_URI')
@@ -199,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 af271d02..2188ce17 100644
--- a/wqflask/wqflask/__init__.py
+++ b/wqflask/wqflask/__init__.py
@@ -14,11 +14,7 @@ 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,