app_config.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import pathlib
  2. from .config import config
  3. from .exception import config_exception
  4. class app_config(config):
  5. def __defaults() -> dict:
  6. return {
  7. "database_uri": "sqlite:///database.db",
  8. "users_file": "users.json",
  9. "covers_dir": "covers/",
  10. "thumbnails_dimension": "400",
  11. "google_api_key": "",
  12. "google_cx": ""
  13. }
  14. def __init__(self):
  15. super().__init__(app_config.__defaults())
  16. @property
  17. def google_api_key(self) -> str | None:
  18. api_key = self._get("google_api_key")
  19. if len(api_key.strip()) == 0:
  20. return None
  21. return api_key
  22. @property
  23. def google_cx(self) -> str | None:
  24. cx = self._get("google_cx")
  25. if len(cx.strip()) == "0":
  26. return None
  27. return cx
  28. @property
  29. def database_uri(self) -> str:
  30. return self._get("database_uri")
  31. @property
  32. def users_file(self) -> str:
  33. return self._get("users_file")
  34. @property
  35. def covers_dir(self) -> str:
  36. return self._get("covers_dir")
  37. @property
  38. def users_path(self) -> pathlib.Path:
  39. return pathlib.Path(self.users_file)
  40. @property
  41. def thumbnails_dimension(self) -> int:
  42. try:
  43. return int(self._get("thumbnails_dimension"))
  44. except:
  45. raise config_exception("Thumbnails dimension must be integer.")
  46. @property
  47. def covers_path(self) -> pathlib.Path:
  48. return pathlib.Path(self.covers_dir)