diff --git a/main.py b/main.py index 4f3373df..3d97b1e3 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ -import asyncio - +# QChatGPT 终端启动入口 +# 在此层级解决依赖项检查。 asciiart = r""" ___ ___ _ _ ___ ___ _____ @@ -11,8 +11,29 @@ asciiart = r""" 📖文档地址: https://q.rkcn.top """ -if __name__ == '__main__': + +async def main_entry(): print(asciiart) + import sys + + from pkg.core.bootutils import deps + + missing_deps = await deps.check_deps() + + if missing_deps: + print("以下依赖包未安装,将自动安装,请完成后重启程序:") + for dep in missing_deps: + print("-", dep) + await deps.install_deps(missing_deps) + print("已自动安装缺失的依赖包,请重启程序。") + sys.exit(0) + from pkg.core import boot - asyncio.run(boot.main()) + await boot.main() + + +if __name__ == '__main__': + import asyncio + + asyncio.run(main_entry()) diff --git a/pkg/core/boot.py b/pkg/core/boot.py index 7a5d965d..7b4318ca 100644 --- a/pkg/core/boot.py +++ b/pkg/core/boot.py @@ -1,10 +1,8 @@ from __future__ import print_function -import os import sys from .bootutils import files -from .bootutils import deps from .bootutils import log from .bootutils import config @@ -38,15 +36,6 @@ async def make_app() -> app.Application: sys.exit(0) - missing_deps = await deps.check_deps() - - if missing_deps: - print("以下依赖包未安装,将自动安装,请完成后重启程序:") - for dep in missing_deps: - print("-", dep) - await deps.install_deps(missing_deps) - sys.exit(0) - qcg_logger = await log.init_logging() # 生成标识符 diff --git a/pkg/core/bootutils/log.py b/pkg/core/bootutils/log.py index 308ca8c4..d7b6da0a 100644 --- a/pkg/core/bootutils/log.py +++ b/pkg/core/bootutils/log.py @@ -16,6 +16,10 @@ log_colors_config = { async def init_logging() -> logging.Logger: + # 删除所有现有的logger + for handler in logging.root.handlers[:]: + logging.root.removeHandler(handler) + level = logging.INFO if "DEBUG" in os.environ and os.environ["DEBUG"] in ["true", "1"]: @@ -46,7 +50,7 @@ async def init_logging() -> logging.Logger: qcg_logger.debug("日志初始化完成,日志级别:%s" % level) logging.basicConfig( - level=logging.INFO, # 设置日志输出格式 + level=logging.CRITICAL, # 设置日志输出格式 format="[DEPR][%(asctime)s.%(msecs)03d] %(pathname)s (%(lineno)d) - [%(levelname)s] :\n%(message)s", # 日志输出的格式 # -8表示占位符,让输出左对齐,输出长度都为8位