Repository navigation
Expand file tree
/
Copy pathquick_setup.py
More file actions
315 lines (256 loc) · 8.77 KB
/
Copy pathquick_setup.py
File metadata and controls
315 lines (256 loc) · 8.77 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env python3
"""
Sum2Slides 一键配置脚本
简化用户配置流程,提供开箱即用的体验
"""
import os
import sys
import shutil
from pathlib import Path
import argparse
def setup_quick_start():
"""快速开始配置"""
print("🚀 Sum2Slides v1.0.1 - 一键配置")
print("=" * 50)
# 获取项目根目录
project_root = Path(__file__).parent.parent
config_dir = project_root / "config"
user_config_dir = Path.home() / ".config" / "sum2slides"
# 创建用户配置目录
user_config_dir.mkdir(parents=True, exist_ok=True)
print(f"✅ 创建配置目录: {user_config_dir}")
# 复制简化配置文件
simple_config = config_dir / "simple.yaml"
user_config = user_config_dir / "config.yaml"
if simple_config.exists():
shutil.copy2(simple_config, user_config)
print(f"✅ 复制配置文件: {user_config}")
else:
print(f"⚠️ 简化配置文件不存在: {simple_config}")
return False
# 创建输出目录
output_dir = project_root / "output"
output_dir.mkdir(exist_ok=True)
print(f"✅ 创建输出目录: {output_dir}")
print("\n🎉 配置完成!")
print("📋 配置信息:")
print(f" - 配置文件: {user_config}")
print(f" - 输出目录: {output_dir}")
print(f" - 日志文件: {user_config_dir / 'sum2slides.log'}")
return True
def setup_preset(preset_name):
"""设置预设配置"""
presets = {
"meeting": {
"template": "business",
"theme": "light",
"max_slides": 6,
"font_size": 14,
"description": "会议演示预设 - 6张幻灯片,商务风格"
},
"business": {
"template": "business",
"theme": "light",
"max_slides": 10,
"font_size": 16,
"description": "商务报告预设 - 10张幻灯片,专业风格"
},
"academic": {
"template": "academic",
"theme": "light",
"max_slides": 12,
"font_size": 14,
"description": "学术报告预设 - 12张幻灯片,学术风格"
},
"tech": {
"template": "default",
"theme": "dark",
"max_slides": 8,
"font_size": 16,
"description": "技术分享预设 - 8张幻灯片,深色主题"
}
}
if preset_name not in presets:
print(f"❌ 无效的预设名称: {preset_name}")
print(f"可用预设: {', '.join(presets.keys())}")
return False
preset = presets[preset_name]
print(f"🎯 设置预设: {preset_name}")
print(f" {preset['description']}")
# 更新用户配置文件
project_root = Path(__file__).parent.parent
user_config_dir = Path.home() / ".config" / "sum2slides"
user_config = user_config_dir / "config.yaml"
if not user_config.exists():
print("⚠️ 用户配置文件不存在,请先运行快速配置")
return False
# 这里简化处理,实际应该更新YAML配置文件
print(f"✅ 应用预设配置:")
print(f" - 模板: {preset['template']}")
print(f" - 主题: {preset['theme']}")
print(f" - 最大幻灯片: {preset['max_slides']}")
print(f" - 字体大小: {preset['font_size']}")
return True
def setup_check_dependencies():
"""检查依赖安装"""
print("🔍 检查依赖...")
dependencies = [
"python-pptx",
"markdown",
"pydantic",
"click",
"pyyaml"
]
missing = []
for dep in dependencies:
try:
__import__(dep.replace("-", "_"))
print(f"✅ {dep}")
except ImportError:
print(f"❌ {dep} - 未安装")
missing.append(dep)
if missing:
print("\n⚠️ 缺少以下依赖:")
for dep in missing:
print(f" - {dep}")
print("\n安装命令:")
print(f"pip install {' '.join(missing)}")
return False
print("\n✅ 所有依赖已安装")
return True
def setup_test_installation():
"""测试安装"""
print("🧪 测试安装...")
try:
# 尝试导入主要模块
from sum2slides import Sum2Slides
print("✅ 导入Sum2Slides模块成功")
# 创建转换器实例
converter = Sum2Slides()
print("✅ 创建转换器实例成功")
# 测试简单转换
test_text = "测试幻灯片\n\n这是一个测试幻灯片"
# 注意:实际转换可能需要处理,这里只测试导入
print("✅ 基本功能测试通过")
return True
except ImportError as e:
print(f"❌ 导入失败: {e}")
print("请确保已正确安装Sum2Slides")
return False
except Exception as e:
print(f"❌ 测试失败: {e}")
return False
def setup_quick_demo():
"""快速演示"""
print("🎬 运行快速演示...")
project_root = Path(__file__).parent.parent
demo_script = project_root / "scripts" / "demo.py"
if demo_script.exists():
print("✅ 演示脚本已找到")
print("运行命令: python scripts/demo.py")
print("\n💡 提示: 您可以单独运行演示脚本查看完整演示")
return True
else:
print(f"❌ 演示脚本未找到: {demo_script}")
return False
def main():
"""主函数"""
parser = argparse.ArgumentParser(
description="Sum2Slides 一键配置脚本",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
使用示例:
# 快速开始配置
python scripts/quick_setup.py
# 设置预设配置
python scripts/quick_setup.py --preset meeting
# 检查依赖
python scripts/quick_setup.py --check-dependencies
# 测试安装
python scripts/quick_setup.py --test-installation
# 查看演示
python scripts/quick_setup.py --demo
"""
)
parser.add_argument(
"--quick-start", "-q",
action="store_true",
help="快速开始配置"
)
parser.add_argument(
"--preset", "-p",
choices=["meeting", "business", "academic", "tech"],
help="设置预设配置"
)
parser.add_argument(
"--check-dependencies", "-c",
action="store_true",
help="检查依赖安装"
)
parser.add_argument(
"--test-installation", "-t",
action="store_true",
help="测试安装"
)
parser.add_argument(
"--demo", "-d",
action="store_true",
help="运行快速演示"
)
parser.add_argument(
"--all", "-a",
action="store_true",
help="运行所有检查和配置"
)
args = parser.parse_args()
# 如果没有指定任何参数,显示帮助
if not any([args.quick_start, args.preset, args.check_dependencies,
args.test_installation, args.demo, args.all]):
parser.print_help()
return
print("🎯 Sum2Slides v1.0.1 - 一键配置工具")
print("=" * 50)
success = True
if args.all:
# 运行所有配置和检查
print("\n📋 执行完整配置流程:")
print("-" * 30)
success &= setup_check_dependencies()
success &= setup_quick_start()
success &= setup_test_installation()
success &= setup_quick_demo()
else:
# 根据参数执行特定操作
if args.quick_start:
print("\n🚀 快速开始配置:")
print("-" * 30)
success &= setup_quick_start()
if args.preset:
print("\n🎯 设置预设配置:")
print("-" * 30)
success &= setup_preset(args.preset)
if args.check_dependencies:
print("\n🔍 检查依赖:")
print("-" * 30)
success &= setup_check_dependencies()
if args.test_installation:
print("\n🧪 测试安装:")
print("-" * 30)
success &= setup_test_installation()
if args.demo:
print("\n🎬 查看演示:")
print("-" * 30)
success &= setup_quick_demo()
# 总结
print("\n" + "=" * 50)
if success:
print("🎉 配置完成!")
print("\n🚀 下一步:")
print(" 1. 运行演示: python scripts/demo.py")
print(" 2. 读取教程: cat TUTORIAL.md")
print(" 3. 开始使用: sum2slides \"你的文本\" --output demo.pptx")
else:
print("⚠️ 配置过程中发现问题")
print("请检查错误信息并重试")
if __name__ == "__main__":
main()