From 3a200f881c300d32f1b594c58ae662182b5fe725 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Wed, 9 May 2018 11:22:38 -0400 Subject: [PATCH] Add support for running the main WSGI application from a virtualenv This is the same behavior as the wsgi-sqlite script, if it is provided with the ARA_WSGI_USE_VIRTUALENV and ARA_WSGI_VIRTUALENV_PATH variables, it will activate it before attempting to import ARA. Change-Id: Ie51e12e492f657531e55b4a7f0eecda503727ee6 --- ara/wsgi.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ara/wsgi.py b/ara/wsgi.py index 957dbacc..92e888f9 100644 --- a/ara/wsgi.py +++ b/ara/wsgi.py @@ -15,14 +15,35 @@ # You should have received a copy of the GNU General Public License # along with ARA. If not, see . -# WSGI file to run the ARA server, it is expected that the server passes an -# ANSIBLE_CONFIG environment variable in order to configure Ansible and ARA. +# WSGI file to run the ARA server. +# It is expected that the server at least passes an ANSIBLE_CONFIG environment +# variable in order to configure Ansible and ARA. + +# Can be configured using environment variables (i.e, Apache SetEnv) with the +# following variables: + +# ARA_WSGI_USE_VIRTUALENV +# Enable virtual environment usage if ARA is installed in a virtual +# environment. +# Defaults to '0', set to '1' to enable. +# ARA_WSGI_VIRTUALENV_PATH +# When using a virtual environment, where the virtualenv is located. +# Defaults to None, set to the absolute path of your virtualenv. import os import logging +import six -from ara.webapp import create_app -from flask import current_app +if (int(os.getenv('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and + os.getenv('ARA_WSGI_VIRTUALENV_PATH')): + activate_this = os.getenv('ARA_WSGI_VIRTUALENV_PATH') + if six.PY2: + execfile(activate_this, dict(__file__=activate_this)) # nosec + else: + exec(open(activate_this).read()) # nosec + +from ara.webapp import create_app # flake8: noqa +from flask import current_app # flake8: noqa log = logging.getLogger(__name__) app = create_app()