import importlib import logging import os import yaml # Check you have a config file if not os.path.isfile("config.yml"): logging.error( "Your config file is missing. Ensure you have copied config-example.yml to config.yml and updated it according to your needs.") exit() # Load config with open("config.yml") as f: config = yaml.safe_load(f) logging.info("Loaded config.") BASE_URL = config["base-url"] MAX_SPOT_AGE = config["max-spot-age-sec"] MAX_ALERT_AGE = config["max-alert-age-sec"] SERVER_OWNER_CALLSIGN = config["server-owner-callsign"] WEB_SERVER_PORT = config["web-server-port"] ALLOW_SPOTTING = config["allow-spotting"] WEB_UI_OPTIONS = config["web-ui-options"] API_ONLY_MODE = config.get("api-only-mode", False) LOG_LEVEL = config.get("log-level", "INFO") LOG_WEB_REQUESTS = config.get("log-web-requests", False) # For ease of config, each spot provider owns its own config about whether it should be enabled by default in the web UI # but for consistency we provide this to the front-end in web-ui-options because it has no impact outside of the web UI. WEB_UI_OPTIONS["spot-providers-enabled-by-default"] = [p["name"] for p in config["spot-providers"] if p["enabled"] and ( "enabled-by-default-in-web-ui" not in p or p["enabled-by-default-in-web-ui"])] # If spotting to this server is enabled, "API" is another valid spot source even though it does not come from # one of our proviers. We set that to also be enabled by default. if ALLOW_SPOTTING: WEB_UI_OPTIONS["spot-providers-enabled-by-default"].append("API") def get_spot_provider_from_config(config_providers_entry): """Utility method to get a spot provider based on the class specified in its config entry.""" module = importlib.import_module('spotproviders.' + config_providers_entry["class"].lower()) provider_class = getattr(module, config_providers_entry["class"]) return provider_class(config_providers_entry) def get_alert_provider_from_config(config_providers_entry): """Utility method to get an alert provider based on the class specified in its config entry.""" module = importlib.import_module('alertproviders.' + config_providers_entry["class"].lower()) provider_class = getattr(module, config_providers_entry["class"]) return provider_class(config_providers_entry) def get_solar_conditions_provider_from_config(config_providers_entry): """Utility method to get a solar conditions provider based on the class specified in its config entry.""" module = importlib.import_module('solarconditionsproviders.' + config_providers_entry["class"].lower()) provider_class = getattr(module, config_providers_entry["class"]) return provider_class(config_providers_entry) def get_static_data_provider_from_config(config_providers_entry): """Utility method to get a static reference data provider based on the class specified in its config entry.""" module = importlib.import_module('staticdataproviders.' + config_providers_entry["class"].lower()) provider_class = getattr(module, config_providers_entry["class"]) return provider_class(config_providers_entry) def get_sig_ref_data_provider_from_config(config_providers_entry): """Utility method to get a SIG reference data provider based on the class specified in its config entry.""" module = importlib.import_module('sigrefdataproviders.' + config_providers_entry["class"].lower()) provider_class = getattr(module, config_providers_entry["class"]) return provider_class(config_providers_entry)