1
0
Files
PPTX/validators/result.py
lanyuanxiaoyao 83ff827ad1 feat: add YAML validation with check command and auto-validation
Implements comprehensive validation before PPTX conversion to catch errors early. Includes element-level validation (colors, fonts, table consistency) and system-level validation (geometry, resources). Supports standalone check command and automatic validation during conversion.
2026-03-02 18:14:45 +08:00

74 lines
2.3 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
验证结果数据结构
定义验证问题和验证结果的数据类。
"""
from dataclasses import dataclass, field
from typing import List
@dataclass
class ValidationIssue:
"""验证问题"""
level: str # "ERROR" | "WARNING" | "INFO"
message: str
location: str # "幻灯片 2, 元素 3"
code: str # "ELEMENT_OUT_OF_BOUNDS"
@dataclass
class ValidationResult:
"""验证结果"""
valid: bool # 是否有 ERROR
errors: List[ValidationIssue] = field(default_factory=list)
warnings: List[ValidationIssue] = field(default_factory=list)
infos: List[ValidationIssue] = field(default_factory=list)
def has_errors(self) -> bool:
"""是否有错误"""
return len(self.errors) > 0
def format_output(self) -> str:
"""格式化为命令行输出"""
lines = []
lines.append("🔍 正在检查 YAML 文件...\n")
# 错误
if self.errors:
lines.append(f"❌ 错误 ({len(self.errors)}):")
for issue in self.errors:
location_str = f"[{issue.location}] " if issue.location else ""
lines.append(f" {location_str}{issue.message}")
lines.append("")
# 警告
if self.warnings:
lines.append(f"⚠️ 警告 ({len(self.warnings)}):")
for issue in self.warnings:
location_str = f"[{issue.location}] " if issue.location else ""
lines.append(f" {location_str}{issue.message}")
lines.append("")
# 提示
if self.infos:
lines.append(f" 提示 ({len(self.infos)}):")
for issue in self.infos:
location_str = f"[{issue.location}] " if issue.location else ""
lines.append(f" {location_str}{issue.message}")
lines.append("")
# 总结
if not self.errors and not self.warnings and not self.infos:
lines.append("✅ 验证通过,未发现问题")
else:
summary_parts = []
if self.errors:
summary_parts.append(f"{len(self.errors)} 个错误")
if self.warnings:
summary_parts.append(f"{len(self.warnings)} 个警告")
lines.append(f"检查完成: 发现 {', '.join(summary_parts)}")
return "\n".join(lines)