Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/storage/api/server.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
import logging | import logging | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.api import (SWHServerAPIApp, error_handler, | from swh.core.api import (RPCServerApp, error_handler, | ||||
encode_data_server as encode_data) | encode_data_server as encode_data) | ||||
from swh.indexer.storage import ( | from swh.indexer.storage import ( | ||||
get_indexer_storage, INDEXER_CFG_KEY, IndexerStorage | get_indexer_storage, INDEXER_CFG_KEY, IndexerStorage | ||||
) | ) | ||||
def get_storage(): | def get_storage(): | ||||
global storage | global storage | ||||
if not storage: | if not storage: | ||||
storage = get_indexer_storage(**app.config[INDEXER_CFG_KEY]) | storage = get_indexer_storage(**app.config[INDEXER_CFG_KEY]) | ||||
return storage | return storage | ||||
app = SWHServerAPIApp(__name__, | app = RPCServerApp(__name__, | ||||
backend_class=IndexerStorage, | backend_class=IndexerStorage, | ||||
backend_factory=get_storage) | backend_factory=get_storage) | ||||
storage = None | storage = None | ||||
@app.errorhandler(Exception) | @app.errorhandler(Exception) | ||||
def my_error_handler(exception): | def my_error_handler(exception): | ||||
return error_handler(exception, encode_data) | return error_handler(exception, encode_data) | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |