mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-11 15:11:41 +00:00
# Conflicts: # core/config.py # core/status_reporter.py # server/handlers/api/options.py # static/js/bands.js # static/js/map.js # static/js/spots.js # templates/status.html
46 lines
2.0 KiB
Python
46 lines
2.0 KiB
Python
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.get("base-url", "http://localhost:8080")
|
|
MAX_SPOT_AGE = config.get("max-spot-age-sec", 3600)
|
|
MAX_ALERT_AGE = config.get("max-alert-age-sec", 604800)
|
|
SERVER_OWNER_CALLSIGN = config.get("server-owner-callsign", "N0CALL")
|
|
WEB_SERVER_PORT = config.get("web-server-port", 8080)
|
|
ALLOW_SPOTTING = config.get("allow-spotting", True)
|
|
ALLOW_UPSTREAM_SPOTTING = config.get("allow-upstream-spotting", True)
|
|
WEB_UI_OPTIONS = config.get("web-ui-options", {})
|
|
API_ONLY_MODE = config.get("api-only-mode", False)
|
|
RECAPTCHA_SECRET_KEY = config.get("recaptcha-secret-key", "")
|
|
RECAPTCHA_SITE_KEY = config.get("recaptcha-site-key", "")
|
|
LOG_LEVEL = config.get("log-level", "INFO")
|
|
LOG_WEB_REQUESTS = config.get("log-web-requests", False)
|
|
|
|
WEB_UI_OPTIONS["qrz-enabled"] = any(p["class"] == "QRZ" and p["enabled"] for p in config["callsign-data-providers"])
|
|
WEB_UI_OPTIONS["hamqth-enabled"] = any(p["class"] == "HamQTH" and p["enabled"] for p in config["callsign-data-providers"])
|
|
WEB_UI_OPTIONS["recaptcha-site-key"] = RECAPTCHA_SITE_KEY
|
|
WEB_UI_OPTIONS["allow-upstream-spotting"] = ALLOW_SPOTTING and ALLOW_UPSTREAM_SPOTTING
|
|
|
|
|
|
def create_provider_from_config(package, config_providers_entry):
|
|
"""Utility method to get a provider based on the class specified in its config entry. You must also provide the
|
|
package to look for it in, as there are several types of provider. e.g. package "providers.spot", where the config
|
|
entry is for a POTA spot provider."""
|
|
|
|
module = importlib.import_module(package + "." + config_providers_entry["class"].lower())
|
|
provider_class = getattr(module, config_providers_entry["class"])
|
|
return provider_class(config_providers_entry)
|