refactor: restructure project to modern Python layout, separate src, tests, docs, examples
This commit is contained in:
109
src/config_man/core/display_manager.py
Normal file
109
src/config_man/core/display_manager.py
Normal file
@@ -0,0 +1,109 @@
|
||||
from typing import Dict, List
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
import json
|
||||
|
||||
|
||||
class DisplayManager:
|
||||
"""显示管理器"""
|
||||
|
||||
def __init__(self):
|
||||
self.console = Console()
|
||||
|
||||
def display_config_comparison(self, version: str, platform: str,
|
||||
storage_config: Dict, cdn_config: Dict,
|
||||
differences: Dict):
|
||||
"""显示配置对比结果"""
|
||||
|
||||
# 创建标题
|
||||
title = f"版本: {version} | 平台: {platform.title()}"
|
||||
self.console.print(f"\n[bold blue]{title}[/bold blue]")
|
||||
|
||||
# 创建表格
|
||||
table = Table(show_header=True, header_style="bold magenta")
|
||||
table.add_column("配置项", style="cyan", width=20)
|
||||
table.add_column("对象存储内容", style="green", width=30)
|
||||
table.add_column("CDN内容", style="yellow", width=30)
|
||||
table.add_column("状态", style="red", width=10)
|
||||
|
||||
# 添加数据行
|
||||
for key, data in differences.items():
|
||||
storage_value = str(data["storage"])
|
||||
cdn_value = str(data["cdn"])
|
||||
status = "❌ 不同" if data["different"] else "✅ 一致"
|
||||
|
||||
# 截断过长的值
|
||||
if len(storage_value) > 25:
|
||||
storage_value = storage_value[:22] + "..."
|
||||
if len(cdn_value) > 25:
|
||||
cdn_value = cdn_value[:22] + "..."
|
||||
|
||||
table.add_row(key, storage_value, cdn_value, status)
|
||||
|
||||
self.console.print(table)
|
||||
|
||||
def display_json_format(self, version: str, platform: str,
|
||||
storage_config: Dict, cdn_config: Dict):
|
||||
"""以JSON格式显示配置"""
|
||||
|
||||
title = f"版本: {version} | 平台: {platform.title()}"
|
||||
self.console.print(f"\n[bold blue]{title}[/bold blue]")
|
||||
|
||||
# 创建对比JSON
|
||||
comparison = {
|
||||
"version": version,
|
||||
"platform": platform,
|
||||
"storage_config": storage_config,
|
||||
"cdn_config": cdn_config
|
||||
}
|
||||
|
||||
# 格式化JSON输出
|
||||
json_str = json.dumps(comparison, indent=2, ensure_ascii=False)
|
||||
|
||||
# 使用面板显示
|
||||
panel = Panel(
|
||||
json_str,
|
||||
title="JSON格式",
|
||||
border_style="blue"
|
||||
)
|
||||
self.console.print(panel)
|
||||
|
||||
def display_summary(self, version: str, results: Dict):
|
||||
"""显示总结信息"""
|
||||
|
||||
self.console.print(f"\n[bold green]配置查看总结[/bold green]")
|
||||
self.console.print(f"版本: {version}")
|
||||
|
||||
for platform in ["android", "ios"]:
|
||||
if platform in results:
|
||||
result = results[platform]
|
||||
if result["success"]:
|
||||
storage_keys = len(result["storage_config"])
|
||||
cdn_keys = len(result["cdn_config"])
|
||||
differences = sum(1 for data in result["differences"].values()
|
||||
if data["different"])
|
||||
|
||||
status = "✅ 正常" if differences == 0 else f"⚠️ {differences} 项不同"
|
||||
|
||||
self.console.print(
|
||||
f" {platform.title()}: {status} "
|
||||
f"(存储: {storage_keys}项, CDN: {cdn_keys}项)"
|
||||
)
|
||||
else:
|
||||
self.console.print(f" {platform.title()}: ❌ 失败")
|
||||
else:
|
||||
self.console.print(f" {platform.title()}: ⚠️ 未检查")
|
||||
|
||||
def display_error(self, message: str):
|
||||
"""显示错误信息"""
|
||||
self.console.print(f"[bold red]错误: {message}[/bold red]")
|
||||
|
||||
def display_warning(self, message: str):
|
||||
"""显示警告信息"""
|
||||
self.console.print(f"[bold yellow]警告: {message}[/bold yellow]")
|
||||
|
||||
def display_info(self, message: str):
|
||||
"""显示信息"""
|
||||
self.console.print(f"[bold blue]信息: {message}[/bold blue]")
|
||||
Reference in New Issue
Block a user