nep框架重构

This commit is contained in:
2025-12-09 01:15:38 +08:00
parent 19a6924a41
commit 91bdb0dab1
30 changed files with 7930 additions and 1001 deletions

47
src/utils.py Normal file
View File

@@ -0,0 +1,47 @@
# src/utils.py
import yaml
import logging
import os
import sys
def load_yaml(path):
"""加载 YAML 配置文件"""
if not os.path.exists(path):
logging.error(f"Config file not found: {path}")
sys.exit(1)
with open(path, 'r') as f:
return yaml.safe_load(f)
def setup_logger(work_dir, log_file="autonep.log"):
"""配置日志:同时输出到文件和控制台"""
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# 清楚之前的 handler 防止重复
if logger.hasHandlers():
logger.handlers.clear()
# 文件 Handler
file_handler = logging.FileHandler(os.path.join(work_dir, log_file))
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
logger.addHandler(file_handler)
# 控制台 Handler
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter('%(message)s')) # 控制台只看消息,简洁点
logger.addHandler(console_handler)
return logger
class Notifier:
"""(预留) 通知模块"""
def __init__(self, url=None):
self.url = url
def send(self, title, msg, priority=5):
# 暂时只打印日志,不实际发送
logging.info(f"[[Notification]] {title}: {msg}")