diff --git a/labmanager/__init__.py b/labmanager/__init__.py index aed55f3..702c6b4 100644 --- a/labmanager/__init__.py +++ b/labmanager/__init__.py @@ -14,7 +14,6 @@ # Import the Flask global application and the configuration # from application import app -import config as _config # # Blueprints (application modules). The following are present: @@ -40,7 +39,7 @@ def load_rlms_modules(): Expand documentation on how to add a new one. """ - if len(_config.RLMS) == 0: + if len(app.config['RLMS']) == 0: print >> sys.stderr, "Warning: RLMS configuration variable empty or not found." print >> sys.stderr, "Warning: This means that this LabManager can not handle any remote lab, which" print >> sys.stderr, "Warning: does not make sense. You should add a RLMS = [] variable in your " @@ -50,7 +49,7 @@ def load_rlms_modules(): import labmanager.rlms.ext.virtual as virtual assert virtual is not None # pyflakes warning - for _rlms in _config.RLMS: + for _rlms in app.config['RLMS']: __import__('labmanager.rlms.ext.%s' % _rlms) # This will register all the RLMSs in the global registry. So it will @@ -69,11 +68,13 @@ def register_blueprints(): for url, blueprint in _BLUEPRINTS.items(): app.register_blueprint(blueprint, url_prefix='/rlms' + url) -def bootstrap(): - load_views() - load_rlms_modules() - register_blueprints() - # print app.url_map +load_views() +load_rlms_modules() +register_blueprints() +# print app.url_map + +# Maintained for compatibility (it might be deployed in certain .wsgi files in other servers) +def bootstrap(): pass def run(): from .db import check_version @@ -83,8 +84,6 @@ def run(): print >> sys.stderr, "And then run this script again" sys.exit(-1) - bootstrap() - parser = optparse.OptionParser(usage = "Run in development mode the LabManager. In production, please use WSGI.") parser.add_option('-p', '--port', dest='port', metavar="PORT", diff --git a/labmanager/application.py b/labmanager/application.py index 74488a8..189dd25 100644 --- a/labmanager/application.py +++ b/labmanager/application.py @@ -15,7 +15,6 @@ import os from flask import Flask, render_template, redirect, url_for -from labmanager.db import db_session app = Flask(__name__) app.config.from_object('config') @@ -74,6 +73,8 @@ def get_timezone(): # # Initialize administration panels # +from labmanager.db import db_session + from .views.admin import init_admin init_admin(app, db_session) diff --git a/labmanager/db.py b/labmanager/db.py index e8df79b..4213b06 100644 --- a/labmanager/db.py +++ b/labmanager/db.py @@ -16,14 +16,14 @@ from sqlalchemy import create_engine, MetaData from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base -from config import SQLALCHEMY_ENGINE_STR, USE_PYMYSQL from labmanager.utils import data_filename +from labmanager.application import app -if USE_PYMYSQL: +if app.config.get('USE_PYMYSQL', False): import pymysql_sa pymysql_sa.make_default_mysql_dialect() -engine = create_engine(SQLALCHEMY_ENGINE_STR, convert_unicode=True, pool_recycle=3600) +engine = create_engine(app.config['SQLALCHEMY_ENGINE_STR'], convert_unicode=True, pool_recycle=3600) db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, @@ -34,8 +34,8 @@ def create_alembic_config(): alembic_config = Config("alembic.ini") alembic_config.set_main_option("script_location", os.path.abspath(data_filename('alembic'))) - alembic_config.set_main_option("url", SQLALCHEMY_ENGINE_STR) - alembic_config.set_main_option("sqlalchemy.url", SQLALCHEMY_ENGINE_STR) + alembic_config.set_main_option("url", app.config['SQLALCHEMY_ENGINE_STR']) + alembic_config.set_main_option("sqlalchemy.url", app.config['SQLALCHEMY_ENGINE_STR']) return alembic_config def init_db(drop = False): @@ -66,7 +66,7 @@ def check_version(): script = ScriptDirectory.from_config(alembic_config) head = script.get_current_head() - engine = create_engine(SQLALCHEMY_ENGINE_STR) + engine = create_engine(app.config['SQLALCHEMY_ENGINE_STR']) context = MigrationContext.configure(engine) current_rev = context.get_current_revision() diff --git a/requirements.txt b/requirements.txt index 625346c..b5c585e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ PyYAML==3.10 SQLAlchemy==0.7.10 alembic==0.6.4 requests==2.1.0 +Flask-Testing==0.4.1 git+https://github.com/gateway4labs/rlms_unr.git git+https://github.com/gateway4labs/rlms_weblabdeusto.git diff --git a/run_wsgi.wsgi b/run_wsgi.wsgi index 877247e..dd98c38 100755 --- a/run_wsgi.wsgi +++ b/run_wsgi.wsgi @@ -12,6 +12,5 @@ os.chdir(LABMANAGER_DIR) import config -from labmanager import app as application, bootstrap -bootstrap() +from labmanager import app as application application.config.from_object('config')