ext.py 1.44 KB
Newer Older
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
5
6
7
8
#
# This file is part of CERN Search.
# Copyright (C) 2018-2019 CERN.
#
# CERN Search is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
9

Carina Antunes's avatar
Carina Antunes committed
10
from cern_search_rest_api.config import LOGGING_CONSOLE_LEVEL
11
12
from cern_search_rest_api.modules.cernsearch.indexer import csas_indexer_receiver
from cern_search_rest_api.modules.cernsearch.views import build_blueprint
Carina Antunes's avatar
Carina Antunes committed
13
from invenio_indexer.signals import before_record_index
Carina Antunes's avatar
Carina Antunes committed
14
from invenio_logging.console import InvenioLoggingConsole
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


class CERNSearch(object):
    """CERN Search extension."""

    def __init__(self, app=None):
        """Extension initialization."""
        if app:
            self.init_app(app)

    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        blueprint = build_blueprint(app)
        app.register_blueprint(blueprint)
30
        before_record_index.connect(csas_indexer_receiver, sender=app)
31
32
        app.extensions["cern-search"] = self

Carina Antunes's avatar
Carina Antunes committed
33
34
35
36
        #InvenioLoggingConsole(app)
        app.logger.setLevel(LOGGING_CONSOLE_LEVEL)
        app.logger.debug('Starting up...')

37
38
39
40
41
    def init_config(self, app):
        """Initialize configuration."""
        # Set up API endpoints for records.
        for k in dir(app.config):
            if k.startswith('CERN_SEARCH'):
Carina Antunes's avatar
Carina Antunes committed
42
                app.config.setdefault(k, getattr(app.config, k))