1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import json
- import logging
- import os
- from typing import Dict
- conf: Dict[str, any] = {
- "SECRET_KEY": "HuanMail-R-Salt",
- "WEBSITE_NAME": "HuanMail",
- "WEBSITE_TITLE": "HuanMail-在线邮件系统",
- "IMAP_HOST": "localhost",
- "IMAP_PORT": 143,
- "IMAP_SSL": False,
- "IMAP_START_SSL": False,
- "SMTP_HOST": "localhost",
- "SMTP_PORT": 25,
- "SMTP_SSL": False,
- "SMTP_START_SSL": False,
- "REDIS_HOST": "localhost",
- "REDIS_PORT": 6379,
- "REDIS_NAME": "localhost",
- "REDIS_PASSWD": "123456",
- "REDIS_DATABASE": 0,
- "LOG_HOME": "",
- "LOG_FORMAT": "[%(levelname)s]:%(name)s:%(asctime)s "
- "(%(filename)s:%(lineno)d %(funcName)s) "
- "%(process)d %(thread)d "
- "%(message)s",
- "LOG_LEVEL": logging.INFO,
- "LOG_STDERR": True,
- "DEBUG_PROFILE": False,
- "LOGO": "HuanMail.ico",
- }
- def configure(conf_file: str, encoding="utf-8"):
- """ 运行配置程序, 该函数需要在其他模块被执行前调用 """
- with open(conf_file, mode="r", encoding=encoding) as f:
- json_str = f.read()
- conf.update(json.loads(json_str))
- if type(conf["LOG_LEVEL"]) is str:
- conf["LOG_LEVEL"] = {"debug": logging.DEBUG,
- "info": logging.INFO,
- "warning": logging.WARNING,
- "error": logging.ERROR}.get(conf["LOG_LEVEL"])
- if len(conf["LOG_HOME"]) > 0:
- os.makedirs(conf["LOG_HOME"], exist_ok=True)
|