Key features implemented: - Updated package metadata and dependencies in PKG-INFO, setup files - Added main.py entry point for backward compatibility with README launch method - Enhanced CLI with config options, system info command, and proper signal handling - Implemented minimal PluginManager loading only plugin-loader core plugin - Refactored PluginLoader to follow minimal core design, removed sandbox/isolation complexity - Updated auto-dependency plugin with safer PL injection mechanism and disabled pl_injection - Removed legacy plugin files (firewall, frp_proxy, ftp_server, multi_lang_deploy, ops_toolbox, security_gateway) as functionality moved to core plugin system - Improved gitignore with comprehensive ignore patterns The changes implement a minimal core framework design where only the plugin-loader is directly loaded by the core, with all other plugins managed through the PL injection mechanism, significantly simplifying the architecture.
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""报告格式化器"""
|
|
|
|
|
|
class ReportFormatter:
|
|
"""报告格式化器"""
|
|
|
|
def __init__(self, format_type: str = "console"):
|
|
self.format_type = format_type
|
|
|
|
def format(self, result: dict) -> str:
|
|
"""格式化报告"""
|
|
if self.format_type == "console":
|
|
return self._format_console(result)
|
|
elif self.format_type == "json":
|
|
return self._format_json(result)
|
|
return str(result)
|
|
|
|
def _format_console(self, result: dict) -> str:
|
|
"""控制台格式"""
|
|
lines = []
|
|
lines.append("=" * 60)
|
|
lines.append("代码审查报告")
|
|
lines.append("=" * 60)
|
|
lines.append(f"扫描文件: {result['files_scanned']}")
|
|
lines.append(f"发现问题: {result['total_issues']}")
|
|
lines.append(f"扫描时间: {result['scan_time']}s")
|
|
lines.append("")
|
|
|
|
# 按严重程度分类
|
|
critical = [i for i in result['issues'] if i['severity'] == 'critical']
|
|
warning = [i for i in result['issues'] if i['severity'] == 'warning']
|
|
info = [i for i in result['issues'] if i['severity'] == 'info']
|
|
|
|
lines.append(f"🔴 严重: {len(critical)}")
|
|
lines.append(f"🟡 警告: {len(warning)}")
|
|
lines.append(f"🔵 提示: {len(info)}")
|
|
lines.append("")
|
|
|
|
if critical:
|
|
lines.append("严重问题:")
|
|
for issue in critical:
|
|
lines.append(f" - {issue['file']}:{issue['line']} - {issue['message']}")
|
|
lines.append("")
|
|
|
|
if warning:
|
|
lines.append("警告:")
|
|
for issue in warning[:10]: # 最多显示10个
|
|
lines.append(f" - {issue['file']}:{issue['line']} - {issue['message']}")
|
|
if len(warning) > 10:
|
|
lines.append(f" ... 还有 {len(warning) - 10} 个警告")
|
|
lines.append("")
|
|
|
|
lines.append("=" * 60)
|
|
return '\n'.join(lines)
|
|
|
|
def _format_json(self, result: dict) -> str:
|
|
"""JSON 格式"""
|
|
import json
|
|
return json.dumps(result, indent=2, ensure_ascii=False)
|