user_guide.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 软著申请材料生成系统 - 用户指导工具
  5. 功能:为用户提供友好的交互式指导,简化整个申请流程
  6. 特点:
  7. - 交互式菜单系统
  8. - 智能操作建议
  9. - 一键式工具调用
  10. - 实时状态反馈
  11. - 新手友好的操作指导
  12. """
  13. import sys
  14. import subprocess
  15. from pathlib import Path
  16. # 颜色输出类
  17. class Colors:
  18. RED = '\033[0;31m'
  19. GREEN = '\033[0;32m'
  20. YELLOW = '\033[1;33m'
  21. BLUE = '\033[0;34m'
  22. PURPLE = '\033[0;35m'
  23. CYAN = '\033[0;36m'
  24. BOLD = '\033[1m'
  25. NC = '\033[0m' # No Color
  26. def print_success(message: str):
  27. print(f"{Colors.GREEN}✓ {message}{Colors.NC}")
  28. def print_info(message: str):
  29. print(f"{Colors.BLUE}ℹ {message}{Colors.NC}")
  30. def print_warning(message: str):
  31. print(f"{Colors.YELLOW}⚠ {message}{Colors.NC}")
  32. def print_error(message: str):
  33. print(f"{Colors.RED}✗ {message}{Colors.NC}")
  34. def print_header(message: str):
  35. print(f"\n{Colors.PURPLE}{Colors.BOLD}{'=' * 80}{Colors.NC}")
  36. print(f"{Colors.PURPLE}{Colors.BOLD}{message.center(80)}{Colors.NC}")
  37. print(f"{Colors.PURPLE}{Colors.BOLD}{'=' * 80}{Colors.NC}")
  38. def print_menu_item(number: int, title: str, description: str):
  39. print(f"{Colors.CYAN}{number:2d}.{Colors.NC} {Colors.BOLD}{title}{Colors.NC}")
  40. print(f" {description}")
  41. def print_separator():
  42. print(f"{Colors.BLUE}{'-' * 80}{Colors.NC}")
  43. class UserGuide:
  44. """用户指导系统"""
  45. def __init__(self):
  46. self.project_root = Path.cwd()
  47. def run_tool(self, tool_path: str, tool_name: str) -> bool:
  48. """运行指定工具"""
  49. if not Path(tool_path).exists():
  50. print_error(f"工具不存在: {tool_path}")
  51. return False
  52. print_info(f"正在运行 {tool_name}...")
  53. print_separator()
  54. try:
  55. result = subprocess.run([sys.executable, tool_path], cwd=self.project_root)
  56. print_separator()
  57. if result.returncode == 0:
  58. print_success(f"{tool_name} 执行完成")
  59. return True
  60. else:
  61. print_warning(f"{tool_name} 执行完成 (退出码: {result.returncode})")
  62. return False
  63. except Exception as e:
  64. print_error(f"{tool_name} 执行失败: {e}")
  65. return False
  66. def show_main_menu(self):
  67. """显示主菜单"""
  68. print_header("软著申请材料生成系统 - 用户指导中心")
  69. print(f"{Colors.GREEN}欢迎使用AI驱动的软件著作权申请材料生成系统!{Colors.NC}")
  70. print(f"{Colors.BLUE}本系统将帮助您生成专业的软著申请材料,包括源代码文档、用户手册等。{Colors.NC}")
  71. print()
  72. print_menu_item(1, "🏥 项目健康诊断", "检查项目状态,自动修复常见问题")
  73. print_menu_item(2, "📝 需求文档质量检查", "验证需求文档质量,获得改进建议")
  74. print_menu_item(3, "📊 质量监控面板", "监控生成进度和代码质量")
  75. print_menu_item(4, "🔧 代码合并工具", "将生成的代码合并为申请文档")
  76. print_menu_item(5, "📋 查看项目状态", "查看当前项目的整体状态")
  77. print_menu_item(6, "💡 获取操作建议", "根据项目状态获得下一步建议")
  78. print_menu_item(7, "📚 查看帮助文档", "查看详细的使用说明")
  79. print_menu_item(0, "🚪 退出系统", "结束使用")
  80. print_separator()
  81. def project_diagnosis(self):
  82. """项目诊断"""
  83. print_header("项目健康诊断")
  84. print_info("这将检查项目的完整性并自动修复发现的问题...")
  85. tool_path = "scripts/validators/project_doctor.py"
  86. success = self.run_tool(tool_path, "项目诊断工具")
  87. if success:
  88. print_info("💡 建议查看生成的 '项目诊断报告.txt' 了解详细信息")
  89. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  90. def requirements_validation(self):
  91. """需求文档验证"""
  92. print_header("需求文档质量检查")
  93. req_file = self.project_root / "requires_docs" / "需求文档.md"
  94. if not req_file.exists():
  95. print_error("需求文档不存在!")
  96. print_info("请先创建 requires_docs/需求文档.md 文件")
  97. print_info("可以运行项目诊断工具自动创建模板")
  98. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  99. return
  100. print_info("正在检查需求文档的质量和完整性...")
  101. tool_path = "scripts/validators/validate_requirements.py"
  102. success = self.run_tool(tool_path, "需求文档验证工具")
  103. if success:
  104. print_info("💡 建议查看生成的质量报告了解详细评估结果")
  105. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  106. def quality_monitoring(self):
  107. """质量监控"""
  108. print_header("质量监控面板")
  109. print_info("正在分析项目进度、代码质量和申请成功率...")
  110. tool_path = "scripts/validators/quality_monitor.py"
  111. success = self.run_tool(tool_path, "质量监控工具")
  112. if success:
  113. print_info("💡 建议查看生成的 '质量监控报告.txt' 了解详细分析")
  114. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  115. def code_merging(self):
  116. """代码合并"""
  117. print_header("代码合并工具")
  118. print_info("可用的合并选项:")
  119. print("1. 合并前端代码")
  120. print("2. 合并后端代码")
  121. print("3. 合并数据库代码")
  122. print("4. 一键合并所有代码")
  123. print("0. 返回主菜单")
  124. while True:
  125. choice = input(f"\n{Colors.CYAN}请选择 (0-4): {Colors.NC}").strip()
  126. if choice == "0":
  127. return
  128. elif choice == "1":
  129. self.run_tool("scripts/generators/merge_frontend_simple.py", "前端代码合并")
  130. break
  131. elif choice == "2":
  132. self.run_tool("scripts/generators/merge_backend_simple.py", "后端代码合并")
  133. break
  134. elif choice == "3":
  135. self.run_tool("scripts/generators/merge_database_simple.py", "数据库代码合并")
  136. break
  137. elif choice == "4":
  138. self.run_tool("scripts/generators/merge_all_simple.py", "全部代码合并")
  139. break
  140. else:
  141. print_warning("无效选择,请输入 0-4")
  142. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  143. def show_project_status(self):
  144. """显示项目状态"""
  145. print_header("项目状态概览")
  146. # 检查关键文件
  147. status_items = [
  148. ("配置文件", "ai-copyright-config.json"),
  149. ("需求文档", "requires_docs/需求文档.md"),
  150. ("框架设计", "process_docs/*框架设计文档.md"),
  151. ("页面清单", "process_docs/页面清单.md"),
  152. ("前端代码", "output_sourcecode/front/*.html"),
  153. ("后端代码", "output_sourcecode/backend/*"),
  154. ("数据库代码", "output_sourcecode/db/*.sql"),
  155. ("前端申请文档", "output_docs/前端源代码.txt"),
  156. ("后端申请文档", "output_docs/后端源代码.txt"),
  157. ("数据库申请文档", "output_docs/数据库源代码.txt")
  158. ]
  159. for name, pattern in status_items:
  160. if '*' in pattern:
  161. matches = list(self.project_root.glob(pattern))
  162. exists = len(matches) > 0
  163. if exists:
  164. print_success(f"{name}: 已生成 ({len(matches)} 个文件)")
  165. else:
  166. print_error(f"{name}: 未生成")
  167. else:
  168. file_path = self.project_root / pattern
  169. if file_path.exists():
  170. size = file_path.stat().st_size
  171. print_success(f"{name}: 已存在 ({size:,} 字节)")
  172. else:
  173. print_error(f"{name}: 不存在")
  174. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  175. def show_recommendations(self):
  176. """显示操作建议"""
  177. print_header("智能操作建议")
  178. # 简单的状态检查逻辑
  179. req_file = self.project_root / "requires_docs" / "需求文档.md"
  180. config_file = self.project_root / "ai-copyright-config.json"
  181. frontend_files = list(self.project_root.glob("output_sourcecode/front/*.html"))
  182. backend_files = list(self.project_root.glob("output_sourcecode/backend/*"))
  183. recommendations = []
  184. if not config_file.exists():
  185. recommendations.append("🔴 首先运行项目诊断工具修复配置问题")
  186. elif not req_file.exists():
  187. recommendations.append("🔴 创建并填写需求文档 (requires_docs/需求文档.md)")
  188. elif req_file.exists():
  189. try:
  190. with open(req_file, 'r', encoding='utf-8') as f:
  191. content = f.read()
  192. if len(content.strip()) < 500:
  193. recommendations.append("🟡 需求文档内容偏少,建议运行质量检查工具")
  194. else:
  195. recommendations.append("✅ 需求文档质量良好")
  196. except:
  197. pass
  198. if not frontend_files and not backend_files:
  199. recommendations.append("🔴 尚未生成代码,请按照工作流程开始生成")
  200. elif frontend_files or backend_files:
  201. merged_frontend = self.project_root / "output_docs" / "前端源代码.txt"
  202. merged_backend = self.project_root / "output_docs" / "后端源代码.txt"
  203. if not merged_frontend.exists() and frontend_files:
  204. recommendations.append("🟡 前端代码已生成,建议运行合并工具")
  205. if not merged_backend.exists() and backend_files:
  206. recommendations.append("🟡 后端代码已生成,建议运行合并工具")
  207. if merged_frontend.exists() and merged_backend.exists():
  208. recommendations.append("✅ 申请材料已准备就绪,可以提交申请")
  209. # 定期检查建议
  210. recommendations.append("💡 建议定期运行质量监控工具跟踪进度")
  211. recommendations.append("💡 遇到问题时可以运行项目诊断工具")
  212. for i, rec in enumerate(recommendations, 1):
  213. print(f"{i:2d}. {rec}")
  214. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  215. def show_help(self):
  216. """显示帮助信息"""
  217. print_header("系统帮助文档")
  218. help_text = f"""
  219. {Colors.BOLD}软著申请材料生成系统使用指南{Colors.NC}
  220. {Colors.CYAN}1. 系统概述{Colors.NC}
  221. 本系统使用AI技术自动生成软件著作权申请所需的全套材料,
  222. 包括源代码文档、用户手册、登记信息表等。
  223. {Colors.CYAN}2. 基本工作流程{Colors.NC}
  224. ① 项目初始化 → ② 填写需求文档 → ③ 生成代码 → ④ 合并申请材料
  225. {Colors.CYAN}3. 主要功能说明{Colors.NC}
  226. 🏥 项目诊断: 检查项目完整性,自动修复配置问题
  227. 📝 质量检查: 验证需求文档质量,提供改进建议
  228. 📊 质量监控: 实时监控生成进度和代码质量
  229. 🔧 代码合并: 将生成的代码整理为申请文档格式
  230. {Colors.CYAN}4. 文件结构说明{Colors.NC}
  231. requires_docs/ - 用户输入的需求文档
  232. process_docs/ - 中间生成的设计文档
  233. output_sourcecode/ - AI生成的源代码
  234. output_docs/ - 最终的申请材料文档
  235. scripts/ - 系统工具脚本
  236. {Colors.CYAN}5. 使用技巧{Colors.NC}
  237. • 详细填写需求文档可以显著提升生成质量
  238. • 定期运行质量检查工具确保文档合规
  239. • 遇到问题优先使用项目诊断工具
  240. • 生成完成后及时运行合并工具
  241. {Colors.CYAN}6. 常见问题解决{Colors.NC}
  242. • 配置文件错误 → 运行项目诊断工具
  243. • 脚本权限问题 → 项目诊断工具会自动修复
  244. • 生成质量不佳 → 改进需求文档后重新生成
  245. • 文件缺失问题 → 检查目录结构和权限设置
  246. {Colors.CYAN}7. 联系支持{Colors.NC}
  247. 如遇到技术问题,请保存诊断报告并联系技术支持。
  248. """
  249. print(help_text)
  250. input(f"\n{Colors.YELLOW}按回车键返回主菜单...{Colors.NC}")
  251. def run(self):
  252. """运行用户指导系统"""
  253. while True:
  254. try:
  255. self.show_main_menu()
  256. choice = input(f"\n{Colors.CYAN}请选择操作 (0-7): {Colors.NC}").strip()
  257. if choice == "0":
  258. print_header("感谢使用软著申请材料生成系统")
  259. print_success("祝您申请顺利!")
  260. break
  261. elif choice == "1":
  262. self.project_diagnosis()
  263. elif choice == "2":
  264. self.requirements_validation()
  265. elif choice == "3":
  266. self.quality_monitoring()
  267. elif choice == "4":
  268. self.code_merging()
  269. elif choice == "5":
  270. self.show_project_status()
  271. elif choice == "6":
  272. self.show_recommendations()
  273. elif choice == "7":
  274. self.show_help()
  275. else:
  276. print_warning("无效选择,请输入 0-7")
  277. input(f"\n{Colors.YELLOW}按回车键继续...{Colors.NC}")
  278. except KeyboardInterrupt:
  279. print(f"\n\n{Colors.YELLOW}用户中断操作{Colors.NC}")
  280. print_success("感谢使用!")
  281. break
  282. except Exception as e:
  283. print_error(f"发生错误: {e}")
  284. input(f"\n{Colors.YELLOW}按回车键继续...{Colors.NC}")
  285. def main():
  286. """主函数"""
  287. if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']:
  288. print("软著申请材料生成系统 - 用户指导工具")
  289. print("\n用法:")
  290. print(" python3 user_guide.py")
  291. print("\n功能:")
  292. print(" 提供交互式用户界面,简化软著申请材料生成流程")
  293. print(" 集成所有系统工具,提供一站式操作体验")
  294. print("\n特点:")
  295. print(" - 友好的交互式菜单")
  296. print(" - 智能操作建议")
  297. print(" - 一键工具调用")
  298. print(" - 实时状态反馈")
  299. return
  300. # 运行用户指导系统
  301. guide = UserGuide()
  302. guide.run()
  303. if __name__ == "__main__":
  304. main()