ai-copyright.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. AI驱动软件著作权申请材料生成系统 - 统一入口脚本
  5. 版本: 1.0
  6. 这是系统的主入口脚本,提供统一的命令行界面来访问所有功能
  7. """
  8. import sys
  9. import argparse
  10. import subprocess
  11. from pathlib import Path
  12. class Colors:
  13. """终端颜色定义"""
  14. RED = '\033[0;31m'
  15. GREEN = '\033[0;32m'
  16. YELLOW = '\033[1;33m'
  17. BLUE = '\033[0;34m'
  18. PURPLE = '\033[0;35m'
  19. CYAN = '\033[0;36m'
  20. NC = '\033[0m'
  21. def print_colored(color, message):
  22. """打印带颜色的消息"""
  23. print(f"{color}{message}{Colors.NC}")
  24. def print_header():
  25. """打印系统标题"""
  26. print_colored(Colors.CYAN, "="*70)
  27. print_colored(Colors.PURPLE, "🤖 AI驱动软件著作权申请材料生成系统")
  28. print_colored(Colors.BLUE, " 统一管理工具 v1.0")
  29. print_colored(Colors.CYAN, "="*70)
  30. def get_script_path():
  31. """获取脚本根目录"""
  32. return Path(__file__).parent.absolute()
  33. def run_command(command, description="执行命令"):
  34. """运行命令并返回结果"""
  35. print_colored(Colors.BLUE, f"🔄 {description}...")
  36. try:
  37. result = subprocess.run(command, shell=True, check=True,
  38. capture_output=False, text=True)
  39. return result.returncode == 0
  40. except subprocess.CalledProcessError as e:
  41. print_colored(Colors.RED, f"❌ 命令执行失败: {e}")
  42. return False
  43. def init_project(args):
  44. """初始化新项目"""
  45. script_path = get_script_path() / "scripts" / "init" / "init_project.py"
  46. if not args.name:
  47. print_colored(Colors.RED, "❌ 请提供项目名称")
  48. print("用法: ai-copyright.py init <项目名称>")
  49. return False
  50. cmd = f"python3 {script_path} {args.name}"
  51. if args.force:
  52. cmd += " --force"
  53. return run_command(cmd, f"初始化项目 '{args.name}'")
  54. def generate_code(args):
  55. """生成源代码"""
  56. script_path = get_script_path() / "scripts" / "generators"
  57. if args.type == "all":
  58. script = script_path / "generate_all_sourcecode.py"
  59. desc = "生成所有源代码"
  60. elif args.type == "frontend":
  61. script = script_path / "generate_frontend_sourcecode.py"
  62. desc = "生成前端源代码"
  63. elif args.type == "backend":
  64. script = script_path / "generate_backend_sourcecode.py"
  65. desc = "生成后端源代码"
  66. else:
  67. print_colored(Colors.RED, "❌ 无效的生成类型")
  68. return False
  69. return run_command(f"python3 {script}", desc)
  70. def check_project(args):
  71. """检查项目"""
  72. script_path = get_script_path() / "scripts" / "validators" / "check_project.py"
  73. cmd = f"python3 {script_path}"
  74. if args.quick:
  75. cmd += " --quick"
  76. if args.path:
  77. cmd += f" {args.path}"
  78. return run_command(cmd, "检查项目完整性")
  79. def run_tests(args):
  80. """运行测试"""
  81. script_path = get_script_path() / "scripts" / "validators" / "run_tests.py"
  82. cmd = f"python3 {script_path}"
  83. if args.path:
  84. cmd += f" {args.path}"
  85. return run_command(cmd, "运行自动化测试")
  86. def validate_frontend(_args):
  87. """验证前端页面"""
  88. script_path = get_script_path() / "scripts" / "validators" / "validate_frontend_pages.py"
  89. return run_command(f"python3 {script_path}", "验证前端页面完整性")
  90. def show_status(_args):
  91. """显示项目状态"""
  92. print_colored(Colors.CYAN, "\n📊 项目状态概览")
  93. print("-" * 50)
  94. # 检查配置文件
  95. config_file = get_script_path() / "ai-copyright-config.json"
  96. template_file = get_script_path() / "config" / "ai-copyright-config.example.json"
  97. if config_file.exists():
  98. print_colored(Colors.GREEN, "✅ 项目配置文件存在")
  99. elif template_file.exists():
  100. print_colored(Colors.YELLOW, "⚠️ 使用模板配置文件,请复制并自定义")
  101. print(f" cp {template_file} {config_file}")
  102. else:
  103. print_colored(Colors.RED, "❌ 配置文件缺失")
  104. # 检查关键目录
  105. dirs_to_check = [
  106. ("requires_docs", "输入文档目录"),
  107. ("output_docs", "输出文档目录"),
  108. ("output_sourcecode", "生成代码目录"),
  109. ("specs_docs", "规范文档目录"),
  110. ("system_prompts", "AI提示词目录")
  111. ]
  112. for dir_name, desc in dirs_to_check:
  113. dir_path = get_script_path() / dir_name
  114. if dir_path.exists():
  115. print_colored(Colors.GREEN, f"✅ {desc} 存在")
  116. else:
  117. print_colored(Colors.RED, f"❌ {desc} 缺失")
  118. return True
  119. def main():
  120. """主函数"""
  121. parser = argparse.ArgumentParser(
  122. description='AI驱动软件著作权申请材料生成系统 - 统一管理工具',
  123. formatter_class=argparse.RawDescriptionHelpFormatter,
  124. epilog="""
  125. 示例用法:
  126. %(prog)s init "我的项目" # 初始化新项目
  127. %(prog)s generate all # 生成所有源代码
  128. %(prog)s generate frontend # 生成前端代码
  129. %(prog)s check --quick # 快速检查项目
  130. %(prog)s test # 运行自动化测试
  131. %(prog)s validate-frontend # 验证前端页面
  132. %(prog)s status # 显示项目状态
  133. """
  134. )
  135. subparsers = parser.add_subparsers(dest='command', help='可用命令')
  136. # init 命令
  137. init_parser = subparsers.add_parser('init', help='初始化新项目')
  138. init_parser.add_argument('name', help='项目名称')
  139. init_parser.add_argument('--force', '-f', action='store_true', help='强制覆盖现有目录')
  140. # generate 命令
  141. gen_parser = subparsers.add_parser('generate', help='生成源代码')
  142. gen_parser.add_argument('type', choices=['all', 'frontend', 'backend'],
  143. help='生成类型')
  144. # check 命令
  145. check_parser = subparsers.add_parser('check', help='检查项目完整性')
  146. check_parser.add_argument('--quick', '-q', action='store_true', help='快速检查')
  147. check_parser.add_argument('path', nargs='?', help='项目路径')
  148. # test 命令
  149. test_parser = subparsers.add_parser('test', help='运行自动化测试')
  150. test_parser.add_argument('path', nargs='?', help='项目路径')
  151. # validate-frontend 命令
  152. subparsers.add_parser('validate-frontend', help='验证前端页面完整性')
  153. # status 命令
  154. subparsers.add_parser('status', help='显示项目状态')
  155. args = parser.parse_args()
  156. print_header()
  157. if not args.command:
  158. print_colored(Colors.YELLOW, "\n⚠️ 未指定命令,显示帮助信息:")
  159. parser.print_help()
  160. return 0
  161. # 执行对应命令
  162. command_map = {
  163. 'init': init_project,
  164. 'generate': generate_code,
  165. 'check': check_project,
  166. 'test': run_tests,
  167. 'validate-frontend': validate_frontend,
  168. 'status': show_status
  169. }
  170. func = command_map.get(args.command)
  171. if func:
  172. success = func(args)
  173. if success:
  174. print_colored(Colors.GREEN, f"\n✅ 命令 '{args.command}' 执行成功")
  175. else:
  176. print_colored(Colors.RED, f"\n❌ 命令 '{args.command}' 执行失败")
  177. return 0 if success else 1
  178. else:
  179. print_colored(Colors.RED, f"❌ 未知命令: {args.command}")
  180. return 1
  181. if __name__ == "__main__":
  182. sys.exit(main())