__init__.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import json
  2. import os
  3. root = os.path.abspath(os.path.join(__file__, '..', '..'))
  4. conf = {
  5. "SECRET_KEY": "HEnglish",
  6. "TITLE": "HEnglish :D",
  7. "FOOTER": "Power by HEnglish",
  8. "ABOUT": "An useful English learning website for personal.",
  9. "DB_TEMPLATE": f"{os.path.join(root, 'resource', 'template')}",
  10. "DB_PATH": f"{os.path.join(root, 'var', 'db')}",
  11. "LOG_HOME": f"{os.path.join(root, 'var', 'log')}",
  12. "LOG_STDERR": True,
  13. "LOG_LEVEL": "DEBUG",
  14. "SERVER_NAME": None,
  15. "MAX_CONTENT_LENGTH": 5 * 1024 * 1024, # Flask 文件上传最大大小
  16. "LOG_FILE_NAME_PID": False,
  17. "INVITE_URL": "12345678",
  18. "ALIYUN_KEY": "",
  19. "ALIYUN_SECRET": "",
  20. "TLS_URL": "",
  21. "TLS_APPID": ""
  22. }
  23. def configure(file_path: str, encoding: str = "utf-8"):
  24. with open(file_path, mode="r", encoding=encoding) as f:
  25. json_str = f.read()
  26. _conf: dict = json.loads(json_str)
  27. conf.update(_conf)
  28. os.makedirs(conf["DB_TEMPLATE"], exist_ok=True)
  29. os.makedirs(conf["DB_PATH"], exist_ok=True)
  30. os.makedirs(conf["LOG_HOME"], exist_ok=True)