app_config.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. }
  12. def __init__(self):
  13. super().__init__(app_config.__defaults())
  14. @property
  15. def database_uri(self) -> str:
  16. return self._get("database_uri")
  17. @property
  18. def users_file(self) -> str:
  19. return self._get("users_file")
  20. @property
  21. def covers_dir(self) -> str:
  22. return self._get("covers_dir")
  23. @property
  24. def users_path(self) -> pathlib.Path:
  25. return pathlib.Path(self.users_file)
  26. @property
  27. def thumbnails_dimension(self) -> int:
  28. try:
  29. return int(self._get("thumbnails_dimension"))
  30. except:
  31. raise config_exception("Thumbnails dimension must be integer.")
  32. @property
  33. def covers_path(self) -> pathlib.Path:
  34. return pathlib.Path(self.covers_dir)