-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_setup.py
More file actions
137 lines (121 loc) · 4.54 KB
/
check_setup.py
File metadata and controls
137 lines (121 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
"""
快速验证脚本 - 检查应用是否正确配置
"""
import os
import sys
from pathlib import Path
def check_file_exists(filepath, description):
"""检查文件是否存在"""
if Path(filepath).exists():
size = Path(filepath).stat().st_size
print(f"✅ {description:30} {filepath:40} ({size} bytes)")
return True
else:
print(f"❌ {description:30} {filepath:40} (缺失)")
return False
def check_content_contains(filepath, content, description):
"""检查文件是否包含特定内容"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
file_content = f.read()
if content in file_content:
print(f"✅ {description:40} 在 {Path(filepath).name}")
return True
else:
print(f"❌ {description:40} 未在 {Path(filepath).name} 中找到")
return False
except Exception as e:
print(f"❌ {description:40} 检查失败: {e}")
return False
def main():
print("🔍 账单转 Beancount 工具 - 配置检查")
print("=" * 90)
all_good = True
# 1. 检查核心文件
print("\n📁 核心文件检查:")
print("-" * 90)
files_to_check = [
('app.py', 'Flask 主应用'),
('requirements.txt', '依赖列表'),
('templates/index.html', 'HTML 模板'),
('static/style.css', 'CSS 样式表'),
('static/script.js', 'JavaScript 脚本'),
('beancount.py', '原始脚本'),
('sample_bills.csv', '示例账单'),
('run.sh', '启动脚本'),
]
for filepath, description in files_to_check:
if not check_file_exists(filepath, description):
all_good = False
# 2. 检查后端功能
print("\n🔧 后端功能检查:")
print("-" * 90)
backend_checks = [
('app.py', 'from flask import', '✅ Flask 导入'),
('app.py', 'def process_bills_stream', '✅ 流式处理函数'),
('app.py', 'json.dumps', '✅ JSON 序列化'),
('app.py', 'stream_with_context', '✅ 流式上下文'),
('app.py', 'mimetype=\'text/event-stream\'', '✅ SSE Content-Type'),
]
for filepath, content, description in backend_checks:
if not check_content_contains(filepath, content, description):
all_good = False
# 3. 检查前端功能
print("\n🎨 前端功能检查:")
print("-" * 90)
frontend_checks = [
('templates/index.html', 'id="streamLogs"', '✅ 日志容器 HTML'),
('static/style.css', '.log-entry', '✅ 日志样式'),
('static/script.js', 'handleStreamData', '✅ 流式数据处理'),
('static/script.js', 'response.body.getReader', '✅ 流式读取 API'),
('static/script.js', 'addLog', '✅ 添加日志函数'),
]
for filepath, content, description in frontend_checks:
if not check_content_contains(filepath, content, description):
all_good = False
# 4. 检查依赖
print("\n📦 依赖检查:")
print("-" * 90)
try:
with open('requirements.txt', 'r') as f:
deps = f.read()
required = ['Flask', 'Flask-CORS', 'deepagents', 'langchain']
for dep in required:
if dep in deps:
print(f"✅ {dep:20} 在 requirements.txt 中")
else:
print(f"⚠️ {dep:20} 未在 requirements.txt 中找到")
all_good = False
except Exception as e:
print(f"❌ 无法读取 requirements.txt: {e}")
all_good = False
# 5. 检查目录结构
print("\n📂 目录结构检查:")
print("-" * 90)
dirs_to_check = [
('output', '输出目录'),
('templates', '模板目录'),
('static', '静态文件目录'),
]
for dirpath, description in dirs_to_check:
if Path(dirpath).exists():
print(f"✅ {description:20} {dirpath}")
else:
print(f"❌ {description:20} {dirpath} (缺失)")
all_good = False
# 总结
print("\n" + "=" * 90)
if all_good:
print("✨ 所有检查通过!应用已准备好运行。")
print("\n🚀 启动命令:")
print(" chmod +x run.sh")
print(" ./run.sh")
print("\n或手动启动:")
print(" python app.py")
return 0
else:
print("⚠️ 有些检查未通过,请查看上面的错误信息。")
return 1
if __name__ == '__main__':
sys.exit(main())