A corporation manager and dashboard for EVE Online
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

43 lignes
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. import yaml
  3. __all__ = ["Config"]
  4. class Config:
  5. """Stores application-wide configuration info."""
  6. def __init__(self, confdir):
  7. self._filename = confdir / "config.yml"
  8. self._data = None
  9. self._load()
  10. def _load(self):
  11. """Load config from the config file."""
  12. with self._filename.open("rb") as fp:
  13. self._data = yaml.load(fp)
  14. def get(self, key="", default=None):
  15. """Acts like a dict lookup in the config file.
  16. Dots can be used to separate keys. For example,
  17. config["foo.bar"] == config["foo"]["bar"].
  18. """
  19. obj = self._data
  20. for item in key.split("."):
  21. if item not in obj:
  22. return default
  23. obj = obj[item]
  24. return obj
  25. @property
  26. def scheme(self):
  27. """Return the site's configured scheme, either "http" or "https"."""
  28. return "https" if self.get("site.https") else "http"
  29. def install(self, app):
  30. """Install relevant config parameters into the application."""
  31. app.config["SERVER_NAME"] = self.get("site.canonical")
  32. app.config["PREFERRED_URL_SCHEME"] = self.scheme
  33. app.secret_key = self.get("auth.session_key")