Ejemplo n.º 1
0
    def get_app_dispatcher(self):
        """
            Initialize the dispatcher with the default app
            and the plugin sub-apps as mounts with
            specific root paths in their urls
        """

        # Applying the processors to the current app instance
        self.apply_pre_processors()
        self.apply_post_processors()
        self.apply_error_handlers()

        # It appears that there must be at least one mount when starting
        # in order to allow adding new mounts during runtime
        self.plugins.update({"/notfound": NotFound()})

        dispatcher = DispatcherMiddleware(self, self.plugins)
        dispatcher.config = self.config
        return dispatcher
Ejemplo n.º 2
0
def create_app(Config):
    """ App creation function """

    instance_path = os.path.abspath('instance')

    app = flask.Flask(__name__)

    global_config = os.path.join(instance_path, Config.CONFIG_FILE)
    app.config.from_object(Config)
    app.config.from_pyfile(global_config)

    # pylint: disable=no-member
    app.logger.setLevel(Config.LOG_LEVEL)
    app.logger.info("Instance path: {ip}".format(ip=instance_path))

    app.register_blueprint(static.bp)
    app.register_blueprint(login.bp)

    app.config.dba = db_tools.PostgreSQLEngine(**app.config)
    user_db_url = app.config.dba.url
    # tell flask_sqlalchemy where the user authentication database is
    app.config['SQLALCHEMY_DATABASE_URI'] = user_db_url

    static.init_app(app)
    do_init_app(app)

    instances = collections.OrderedDict()
    extra_files = [instance_path + '/' + Config.CONFIG_FILE]

    for fn in glob.glob(instance_path + '/*.conf'):
        extra_files.append(fn)
        fn = os.path.basename(fn)
        if fn == Config.CONFIG_FILE:
            continue

        sub_app = flask.Flask(__name__)
        sub_app.config.from_object(Config)
        sub_app.config.from_pyfile(global_config)
        sub_app.config.from_pyfile(os.path.join(instance_path, fn))
        sub_app.config['CONFIG_FILE'] = fn
        sub_app.config['APPLICATION_DIR'] = sub_app.config['APPLICATION_ROOT']
        sub_app.config['APPLICATION_ROOT'] = os.path.join(
            app.config['APPLICATION_ROOT'], sub_app.config['APPLICATION_ROOT'])
        sub_app.register_blueprint(main.bp)
        sub_app.register_blueprint(textflow.bp)
        sub_app.register_blueprint(comparison.bp)
        sub_app.register_blueprint(editor.bp)
        sub_app.register_blueprint(set_cover.bp)
        sub_app.register_blueprint(checks.bp)

        sub_app.config.dba = db_tools.PostgreSQLEngine(**sub_app.config)
        sub_app.config['SQLALCHEMY_DATABASE_URI'] = user_db_url

        do_init_app(sub_app)
        main.init_app(sub_app)
        textflow.init_app(sub_app)
        comparison.init_app(sub_app)
        editor.init_app(sub_app)
        set_cover.init_app(sub_app)
        checks.init_app(sub_app)

        instances[sub_app.config['APPLICATION_ROOT']] = sub_app

    info_app = flask.Flask(__name__)
    info_app.config.update(app.config)
    info_app.register_blueprint(info.bp)
    do_init_app(info_app)
    info.init_app(app, instances)

    instances[app.config['APPLICATION_ROOT']] = info_app

    d = DispatcherMiddleware(app, instances)
    d.config = app.config
    d.config['EXTRA_FILES'] = extra_files
    return d