Changeset View
Changeset View
Standalone View
Standalone View
swh/web/config.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 | |||||
from swh.core import config | from swh.core import config | ||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from swh.indexer.storage import get_indexer_storage | from swh.indexer.storage import get_indexer_storage | ||||
from swh.vault import get_vault | from swh.vault import get_vault | ||||
from swh.scheduler import get_scheduler | from swh.scheduler import get_scheduler | ||||
DEFAULT_CONFIG = { | DEFAULT_CONFIG = { | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | DEFAULT_CONFIG = { | ||||
}), | }), | ||||
'coverage_count_origins': ('bool', False) | 'coverage_count_origins': ('bool', False) | ||||
} | } | ||||
swhweb_config = {} | swhweb_config = {} | ||||
def get_config(config_file='web/web'): | def get_config(config_file='web/web'): | ||||
"""Read the configuration file `config_file`, update the app with | """Read the configuration file `config_file`. | ||||
parameters (secret_key, conf) and return the parsed configuration as a | |||||
dict. If no configuration file is provided, return a default | If an environment variable SWH_CONFIG_FILENAME is defined, this | ||||
configuration.""" | takes precedence over the config_file parameter. | ||||
In any case, update the app with parameters (secret_key, conf) | |||||
and return the parsed configuration as a dict. | |||||
If no configuration file is provided, return a default | |||||
configuration. | |||||
""" | |||||
if not swhweb_config: | if not swhweb_config: | ||||
config_filename = os.environ.get('SWH_CONFIG_FILENAME') | |||||
if config_filename: | |||||
config_file = config_filename | |||||
cfg = config.load_named_config(config_file, DEFAULT_CONFIG) | cfg = config.load_named_config(config_file, DEFAULT_CONFIG) | ||||
swhweb_config.update(cfg) | swhweb_config.update(cfg) | ||||
config.prepare_folders(swhweb_config, 'log_dir') | config.prepare_folders(swhweb_config, 'log_dir') | ||||
swhweb_config['storage'] = get_storage(**swhweb_config['storage']) | swhweb_config['storage'] = get_storage(**swhweb_config['storage']) | ||||
swhweb_config['vault'] = get_vault(**swhweb_config['vault']) | swhweb_config['vault'] = get_vault(**swhweb_config['vault']) | ||||
swhweb_config['indexer_storage'] = \ | swhweb_config['indexer_storage'] = \ | ||||
get_indexer_storage(**swhweb_config['indexer_storage']) | get_indexer_storage(**swhweb_config['indexer_storage']) | ||||
swhweb_config['scheduler'] = get_scheduler(**swhweb_config['scheduler']) # noqa | swhweb_config['scheduler'] = get_scheduler( | ||||
**swhweb_config['scheduler']) | |||||
return swhweb_config | return swhweb_config | ||||
def storage(): | def storage(): | ||||
"""Return the current application's storage. | """Return the current application's storage. | ||||
""" | """ | ||||
return get_config()['storage'] | return get_config()['storage'] | ||||
Show All 21 Lines |