A corporation manager and dashboard for EVE Online
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

43 lines
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")