Skip to content
Snippets Groups Projects

Added feature to retrieve ID of aggregated source name in config file

Merged Cecilia Nievas requested to merge feature/source_id into master
2 unresolved threads
11 files
+ 371
1
Compare changes
  • Side-by-side
  • Inline
Files
11
+ 81
0
#!/usr/bin/env python3
# Copyright (C) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
from gdeimporter.tools.configuration_methods import ConfigurationMethods
logger = logging.getLogger()
class Configuration:
"""This class handles the configuration parameters of the gde-core.
Attributes:
self.model_name (str):
Name of the input aggregated model.
self.database_gde_tiles (dict):
Dictionary containing the credentials needed to connect to the SQL database in which
information on the GDE tiles is stored. The exact parameters needed depend on the
database. They can be:
host (str):
SQL database host address.
dbname (str):
Name of the SQL database.
port (int):
Port where the SQL database can be found.
username (str):
User name to connect to the SQL database.
password (str):
Password associated with self.username.
"""
REQUIRES = [
"model_name",
"database_gde_tiles",
]
def __init__(self, filepath, force_config_over_hierarchies=False):
"""
Args:
filepath (str):
Full file path to the .yml configuration file.
force_config_over_hierarchies (bool):
If True, the contents of the .yml configuration file specified in filepath will
take precedence over any other hierarchy (e.g. preference of environment
variables if they exist). If False, hierarchies of preference established in
this class are applied. This parameter is used for forcing the testing of this
class under certain circumstances. Default: False.
"""
config = ConfigurationMethods.read_config_file(filepath)
self.model_name = ConfigurationMethods.assign_parameter(config, "model_name")
self.database_gde_tiles = ConfigurationMethods.retrieve_database_credentials(
config, "database_gde_tiles", "test_db_gde_tiles.env", force_config_over_hierarchies
)
# Terminate if critical parameters are missing (not all parameters are critical)
for key_parameter in self.REQUIRES:
if getattr(self, key_parameter) is None:
error_message = (
"Error: parameter '%s' could not be retrieved from "
"configuration file. The program cannot run." % (key_parameter)
)
logger.critical(error_message)
raise OSError(error_message)
Loading