refactor: 重构文件读取和日志处理以提升性能和稳定性

- 新增 smart_read_excel 工具函数,统一 Excel 读取逻辑并自动选择引擎
- 重构 ConfigManager.get_path 方法,使用 pathlib 提升路径处理可靠性
- 将 GUI 日志处理改为异步队列模式,避免 UI 阻塞
- 优化 ExcelProcessor 的表头识别逻辑,避免重复读取文件
- 更新配置文件中的版本号
This commit is contained in:
2026-03-30 11:17:25 +08:00
parent bfccdd3a37
commit b7bce93995
8 changed files with 101 additions and 46 deletions
+18 -14
View File
@@ -117,25 +117,29 @@ class ConfigManager:
获取路径配置并确保它是一个有效的绝对路径
如果create为True,则自动创建该目录
"""
path = self.get(section, option, fallback)
from pathlib import Path
path_str = self.get(section, option, fallback)
path = Path(path_str)
if not os.path.isabs(path):
# 相对路径,转为绝对路径
path = os.path.abspath(path)
if not path.is_absolute():
# 相对路径,转为绝对路径(相对于项目根目录)
path = Path(os.getcwd()) / path
if create and not os.path.exists(path):
if create:
try:
# 如果是文件路径,创建其父目录
if '.' in os.path.basename(path):
directory = os.path.dirname(path)
if directory and not os.path.exists(directory):
os.makedirs(directory, exist_ok=True)
logger.info(f"已创建目录: {directory}")
# 智能判断是文件还是目录
# 如果有后缀名则认为是文件,创建其父目录
if path.suffix:
directory = path.parent
if not directory.exists():
directory.mkdir(parents=True, exist_ok=True)
logger.info(f"已创建父目录: {directory}")
else:
# 否则认为是目录路径
os.makedirs(path, exist_ok=True)
logger.info(f"已创建目录: {path}")
if not path.exists():
path.mkdir(parents=True, exist_ok=True)
logger.info(f"已创建目录: {path}")
except Exception as e:
logger.error(f"创建目录失败: {path}, 错误: {e}")
return path
return str(path.absolute())