示例#1
0
文件: app.py 项目: erinmayhood/osf.io
def init_app(settings_module='website.settings',
             set_backends=True,
             routes=True,
             mfr=False,
             attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    build_js_config_files(settings)

    app.debug = settings.DEBUG_MODE

    if mfr:
        init_mfr(app)

    if set_backends:
        logger.debug('Setting storage backends')
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
    apply_middlewares(app, settings)
    return app
示例#2
0
def init_app(settings_module='website.settings', set_backends=True, routes=True,
             attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    with open(os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp:
        json.dump(settings.NODE_CATEGORY_MAP, fp)

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings')
    django.setup()

    app.debug = settings.DEBUG_MODE

    # default config for flask app, however, this does not affect setting cookie using set_cookie()
    app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE
    app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY

    if set_backends:
        do_set_backends(settings)
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
        ensure_licenses()
    apply_middlewares(app, settings)

    return app
示例#3
0
文件: app.py 项目: ccfair/osf.io
def init_app(settings_module='website.settings',
             set_backends=True,
             routes=True,
             attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    with open(
            os.path.join(settings.STATIC_FOLDER, 'built',
                         'nodeCategories.json'), 'wb') as fp:
        json.dump(settings.NODE_CATEGORY_MAP, fp)

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings')
    django.setup()

    app.debug = settings.DEBUG_MODE

    if set_backends:
        do_set_backends(settings)
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
        ensure_licenses()
    apply_middlewares(app, settings)

    return app
示例#4
0
文件: app.py 项目: erinmayhood/osf.io
def init_app(settings_module='website.settings', set_backends=True, routes=True, mfr=False,
        attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    build_js_config_files(settings)

    app.debug = settings.DEBUG_MODE

    if mfr:
        init_mfr(app)

    if set_backends:
        logger.debug('Setting storage backends')
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
    apply_middlewares(app, settings)
    return app
示例#5
0
文件: app.py 项目: 545zhou/osf.io
def init_app(settings_module='website.settings', set_backends=True, routes=True,
             attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    build_js_config_files(settings)

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings')
    django.setup()

    app.debug = settings.DEBUG_MODE

    if set_backends:
        do_set_backends(settings)
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
        ensure_licenses()
    apply_middlewares(app, settings)

    return app
示例#6
0
文件: app.py 项目: scooley/osf.io
def init_app(settings_module='website.settings',
             set_backends=True,
             routes=True,
             attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    logger.info(
        'Initializing the application from process {}, thread {}.'.format(
            os.getpid(), thread.get_ident()))

    # The settings module
    settings = importlib.import_module(settings_module)

    init_addons(settings, routes)
    with open(
            os.path.join(settings.STATIC_FOLDER, 'built',
                         'nodeCategories.json'), 'wb') as fp:
        json.dump(settings.NODE_CATEGORY_MAP, fp)

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings')
    django.setup()

    app.debug = settings.DEBUG_MODE

    # default config for flask app, however, this does not affect setting cookie using set_cookie()
    app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE
    app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY

    if set_backends:
        do_set_backends(settings)
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
        ensure_licenses()
    apply_middlewares(app, settings)

    return app