""" 시스템 설정 검증 스크립트 실제 실행 전에 모든 구성 요소가 올바른지 확인합니다. """ import sys from pathlib import Path import os # 프로젝트 루트를 Python 경로에 추가 project_root = Path(__file__).parent.parent sys.path.insert(0, str(project_root)) def check_file_structure(): """파일 구조 확인""" print("=" * 80) print("1️⃣ 파일 구조 검증") print("=" * 80) required_files = [ "app/main.py", "app/metacognitive_agent.py", "app/rag_pipeline.py", "app/api/routes.py", "app/api/models.py", "services/pdf_processor.py", "services/chunker.py", "services/embedder.py", "services/vector_store.py", "utils/config.py", "scripts/index_pdfs.py", "requirements.txt", ".env.example" ] missing = [] for file in required_files: filepath = project_root / file if filepath.exists(): print(f"✅ {file}") else: print(f"❌ {file} - 누락!") missing.append(file) if missing: print(f"\n⚠️ {len(missing)}개 파일 누락") return False else: print(f"\n✅ 모든 필수 파일 존재 ({len(required_files)}개)") return True def check_env_file(): """환경 변수 파일 확인""" print("\n" + "=" * 80) print("2️⃣ 환경 변수 검증") print("=" * 80) env_file = project_root / ".env" env_example = project_root / ".env.example" if not env_file.exists(): print("⚠️ .env 파일이 없습니다") print(" cp .env.example .env 를 실행하세요") return False print("✅ .env 파일 존재") # .env 파일 내용 확인 with open(env_file) as f: content = f.read() required_keys = [ "ANTHROPIC_API_KEY", "PDF_SOURCE_PATH", "CHROMA_PERSIST_DIRECTORY", "EMBEDDING_MODEL" ] for key in required_keys: if key in content: # 값이 설정되었는지 확인 for line in content.split('\n'): if line.startswith(key): value = line.split('=', 1)[1].strip() if value and not value.startswith('your_'): print(f"✅ {key}: 설정됨") else: print(f"⚠️ {key}: 값 필요") else: print(f"❌ {key}: 누락") return True def check_code_syntax(): """Python 코드 구문 검증""" print("\n" + "=" * 80) print("3️⃣ Python 코드 구문 검증") print("=" * 80) python_files = list(project_root.glob("**/*.py")) errors = [] for py_file in python_files: if 'venv' in str(py_file) or '__pycache__' in str(py_file): continue try: with open(py_file) as f: compile(f.read(), str(py_file), 'exec') print(f"✅ {py_file.relative_to(project_root)}") except SyntaxError as e: print(f"❌ {py_file.relative_to(project_root)}: {e}") errors.append((py_file, e)) if errors: print(f"\n❌ {len(errors)}개 파일에 구문 오류") return False else: print(f"\n✅ 모든 Python 파일 구문 정상 ({len(python_files)}개)") return True def check_directories(): """필수 디렉토리 확인""" print("\n" + "=" * 80) print("4️⃣ 디렉토리 구조 검증") print("=" * 80) required_dirs = [ "app", "app/api", "services", "utils", "scripts", "data" ] for dir_name in required_dirs: dir_path = project_root / dir_name if dir_path.exists() and dir_path.is_dir(): print(f"✅ {dir_name}/") else: print(f"❌ {dir_name}/ - 누락!") return False print(f"\n✅ 모든 디렉토리 존재") return True def check_shell_scripts(): """Shell 스크립트 확인""" print("\n" + "=" * 80) print("5️⃣ Shell 스크립트 검증") print("=" * 80) scripts = [ "setup.sh", "run_indexing.sh", "run_server.sh", "upload_to_github.sh" ] for script in scripts: script_path = project_root / script if script_path.exists(): # 실행 권한 확인 if os.access(script_path, os.X_OK): print(f"✅ {script} (실행 가능)") else: print(f"⚠️ {script} (실행 권한 없음)") else: print(f"❌ {script} - 누락!") return True def main(): """전체 검증 실행""" print("\n") print("╔" + "=" * 78 + "╗") print("║" + " " * 20 + "시스템 설정 검증" + " " * 43 + "║") print("╚" + "=" * 78 + "╝") print() results = [] results.append(("파일 구조", check_file_structure())) results.append(("환경 변수", check_env_file())) results.append(("코드 구문", check_code_syntax())) results.append(("디렉토리", check_directories())) results.append(("Shell 스크립트", check_shell_scripts())) # 최종 결과 print("\n" + "=" * 80) print("📊 검증 결과") print("=" * 80) for name, result in results: status = "✅ 통과" if result else "❌ 실패" print(f"{name:15} : {status}") all_passed = all(result for _, result in results) print("=" * 80) if all_passed: print("✅ 모든 검증 통과!") print("\n다음 단계:") print("1. .env 파일에 API 키 입력") print("2. ./run_indexing.sh 실행 (PDF 인덱싱)") print("3. ./run_server.sh 실행 (API 서버)") else: print("❌ 일부 검증 실패") print("위의 오류를 수정하세요.") print("=" * 80) if __name__ == "__main__": main()