def initialize(*args, **kwargs): """ Initializes Flask and returns the given function with the correct context in order to run """ # FIXME: This is from flaskshell.py # We kept the db initialization functions here instead of import * # as it could be good to keep it in case flaskshell will provide a function # instead of using import * # STEP 1 - Import Invenio Flask Application constructor and database object. from invenio.webinterface_handler_flask import create_invenio_flask_app from invenio.sqlalchemyutils import db # STEP 2 - Create application object and initialize database. app = create_invenio_flask_app() db.init_invenio() db.init_cfg(app) db.init_app(app) # STEP 3 - Create fake application request context and use it. ctx = app.test_request_context() ctx.push() # For explanation see: http://flask.pocoo.org/docs/shell/#firing-before-after-request app.preprocess_request() with app.app_context(): return f(*args, **kwargs)
def wsgi_handler_test(port=80): """ Simple WSGI testing environment based on wsgiref. """ check_wsgiref_testing_feasability() from invenio.webinterface_handler_flask import create_invenio_flask_app app = create_invenio_flask_app(wsgi_serve_static_files=True) app.run(debug=True, port=port)
def main(): from invenio.config import CFG_SITE_SECRET_KEY from invenio.webinterface_handler_flask import create_invenio_flask_app if not CFG_SITE_SECRET_KEY or CFG_SITE_SECRET_KEY == '': CFG_SITE_SECRET_KEY = generate_secret_key() app = create_invenio_flask_app(SECRET_KEY=CFG_SITE_SECRET_KEY) manager.app = app manager.run()
def _init_flask(self): """ Initialize Flask application. The Flask application should only be created in the workers, thus this method should not be called from the __init__ method. """ if not self.flask_app: from flask import current_app if current_app: self.flask_app = current_app else: from invenio.webinterface_handler_flask import create_invenio_flask_app self.flask_app = create_invenio_flask_app() from invenio.sqlalchemyutils import db self.db = db
def create_app(self): app = create_invenio_flask_app(CFG_DATABASE_TYPE=self.engine, SQLALCHEMY_DATABASE_URI=self.SQLALCHEMY_DATABASE_URI) app.testing = True return app
## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. import sys from invenio.config import CFG_SITE_SECRET_KEY from invenio.scriptutils import Manager, change_command_name, \ generate_secret_key, register_manager from invenio.sqlalchemyutils import db from invenio.webinterface_handler_flask import create_invenio_flask_app # Fixes problems with empty secret key in config manager. if 'config' in sys.argv and \ (not CFG_SITE_SECRET_KEY or CFG_SITE_SECRET_KEY == ''): create_invenio_flask_app = create_invenio_flask_app( SECRET_KEY=generate_secret_key()) manager = Manager(create_invenio_flask_app, with_default_commands=False) register_manager(manager) @manager.shell def make_shell_context(): """Extend shell context.""" from flask import current_app return dict(current_app=current_app, db=db) @manager.command def version(): """ Get running version of Invenio """
def main(): from invenio.webinterface_handler_flask import create_invenio_flask_app app = create_invenio_flask_app() manager.app = app manager.run()
## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """ This module implement a helper for interactive shell or commandline tools. """ from flask import has_app_context if not has_app_context(): # STEP 1 - Import Invenio Flask Application constructor and database object. from invenio.webinterface_handler_flask import create_invenio_flask_app # STEP 2 - Create application object and initialize database. app = create_invenio_flask_app() # STEP 3 - Create fake application request context and use it. ctx = app.test_request_context() ctx.push() # For explanation see: http://flask.pocoo.org/docs/shell/#firing-before-after-request app.preprocess_request()