|
|
|
|
|
""" |
|
|
Verification script for the Enhanced DOCX to PDF Converter |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
def verify_directory_structure(): |
|
|
"""Verify that all required directories and files exist""" |
|
|
print("Verifying directory structure...") |
|
|
|
|
|
required_dirs = [ |
|
|
"src", |
|
|
"src/api", |
|
|
"src/utils", |
|
|
"tests", |
|
|
"conversions" |
|
|
] |
|
|
|
|
|
required_files = [ |
|
|
"src/api/main.py", |
|
|
"src/api/app.py", |
|
|
"src/utils/config.py", |
|
|
"src/utils/converter.py", |
|
|
"src/utils/file_handler.py", |
|
|
"tests/test_converter.py", |
|
|
"Dockerfile", |
|
|
"docker-compose.yml", |
|
|
"requirements.txt", |
|
|
"README.md" |
|
|
] |
|
|
|
|
|
|
|
|
for dir_path in required_dirs: |
|
|
if not os.path.exists(dir_path): |
|
|
print(f"❌ Missing directory: {dir_path}") |
|
|
return False |
|
|
print(f"✅ Found directory: {dir_path}") |
|
|
|
|
|
|
|
|
for file_path in required_files: |
|
|
if not os.path.exists(file_path): |
|
|
print(f"❌ Missing file: {file_path}") |
|
|
return False |
|
|
print(f"✅ Found file: {file_path}") |
|
|
|
|
|
return True |
|
|
|
|
|
def verify_python_compilation(): |
|
|
"""Verify that all Python files compile without syntax errors""" |
|
|
print("\nVerifying Python compilation...") |
|
|
|
|
|
python_files = [ |
|
|
"src/api/main.py", |
|
|
"src/api/app.py", |
|
|
"src/utils/config.py", |
|
|
"src/utils/converter.py", |
|
|
"src/utils/file_handler.py", |
|
|
"tests/test_converter.py" |
|
|
] |
|
|
|
|
|
for file_path in python_files: |
|
|
try: |
|
|
with open(file_path, 'r', encoding='utf-8') as f: |
|
|
compile(f.read(), file_path, 'exec') |
|
|
print(f"✅ Compiles successfully: {file_path}") |
|
|
except Exception as e: |
|
|
print(f"❌ Compilation error in {file_path}: {e}") |
|
|
return False |
|
|
|
|
|
return True |
|
|
|
|
|
def verify_docker_files(): |
|
|
"""Verify Docker configuration files""" |
|
|
print("\nVerifying Docker configuration...") |
|
|
|
|
|
|
|
|
try: |
|
|
with open("Dockerfile", "r") as f: |
|
|
content = f.read() |
|
|
if "FROM ubuntu:22.04" in content and "libreoffice" in content: |
|
|
print("✅ Dockerfile appears to be correctly configured") |
|
|
else: |
|
|
print("⚠️ Dockerfile may be missing key components") |
|
|
except Exception as e: |
|
|
print(f"❌ Error reading Dockerfile: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
try: |
|
|
with open("docker-compose.yml", "r") as f: |
|
|
content = f.read() |
|
|
if "docx-to-pdf-enhanced" in content and "8000:8000" in content: |
|
|
print("✅ docker-compose.yml appears to be correctly configured") |
|
|
else: |
|
|
print("⚠️ docker-compose.yml may be missing key components") |
|
|
except Exception as e: |
|
|
print(f"❌ Error reading docker-compose.yml: {e}") |
|
|
return False |
|
|
|
|
|
return True |
|
|
|
|
|
def verify_requirements(): |
|
|
"""Verify requirements file""" |
|
|
print("\nVerifying requirements...") |
|
|
|
|
|
try: |
|
|
with open("requirements.txt", "r") as f: |
|
|
content = f.read() |
|
|
required_packages = ["fastapi", "uvicorn", "python-multipart"] |
|
|
|
|
|
for package in required_packages: |
|
|
if package in content: |
|
|
print(f"✅ Found required package: {package}") |
|
|
else: |
|
|
print(f"❌ Missing required package: {package}") |
|
|
return False |
|
|
|
|
|
print("✅ All required packages found in requirements.txt") |
|
|
return True |
|
|
except Exception as e: |
|
|
print(f"❌ Error reading requirements.txt: {e}") |
|
|
return False |
|
|
|
|
|
def main(): |
|
|
"""Main verification function""" |
|
|
print("Enhanced DOCX to PDF Converter - Setup Verification") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
checks = [ |
|
|
verify_directory_structure, |
|
|
verify_python_compilation, |
|
|
verify_docker_files, |
|
|
verify_requirements |
|
|
] |
|
|
|
|
|
all_passed = True |
|
|
for check in checks: |
|
|
if not check(): |
|
|
all_passed = False |
|
|
|
|
|
print("\n" + "=" * 50) |
|
|
if all_passed: |
|
|
print("✅ All verification checks passed!") |
|
|
print("\nYour Enhanced DOCX to PDF Converter is ready for use.") |
|
|
print("To start the service, run:") |
|
|
print(" docker-compose up --build") |
|
|
print("\nThen access the API at http://localhost:8000") |
|
|
print("API documentation is available at http://localhost:8000/docs") |
|
|
else: |
|
|
print("❌ Some verification checks failed.") |
|
|
print("Please review the errors above and correct them before proceeding.") |
|
|
|
|
|
return all_passed |
|
|
|
|
|
if __name__ == "__main__": |
|
|
success = main() |
|
|
sys.exit(0 if success else 1) |