database.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright 2021 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import TYPE_CHECKING
  15. if TYPE_CHECKING:
  16. from configparser import ConfigParser
  17. class DatabaseConfig:
  18. def parse_config(self, cfg: "ConfigParser") -> None:
  19. """
  20. Parse the database section of the config
  21. :param cfg: the configuration to be parsed
  22. """
  23. self.database_path = cfg.get("db", "db.file")
  24. def generate_config_section(
  25. self,
  26. db_path: str,
  27. **kwargs,
  28. ) -> str:
  29. """
  30. Generate the database config section
  31. :param db_path: The SQLite Database file for Sydent to use.
  32. :return: the yaml config section
  33. """
  34. return (
  35. """\
  36. ## Database ##
  37. # The path to the SQLite database file for Sydent to use.
  38. # It can be set to ':memory:' to use a temporary database
  39. # in RAM instead of on disk. Required.
  40. #
  41. database_path: %(db_path)s
  42. """
  43. % locals()
  44. )