Spaces:
Sleeping
Sleeping
File size: 3,506 Bytes
830be50 63b8c2c 830be50 | 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 | #!/usr/bin/env python3
"""
Test script to verify configuration paths and directory structure.
Run this before deployment to catch path issues early.
"""
import sys
from pathlib import Path
# Add the cardserver directory to the path so we can import our modules
sys.path.insert(0, str(Path(__file__).parent.parent))
try:
from app.core.config import settings
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_paths():
"""Test all configured paths and create directories if needed."""
logger.info("Testing configuration paths...")
logger.info(f"Current working directory: {Path.cwd()}")
logger.info(f"Script location: {Path(__file__).resolve()}")
paths_to_test = [
("Model Path", settings.resolved_model_path),
("Generated Images Path", settings.resolved_generated_path),
("Base Images Path", settings.resolved_base_path),
("Symbols Path", settings.resolved_symbols_path),
("QR Codes Path", settings.resolved_qr_code_path),
("Static Files Mount Dir", settings.resolved_static_files_mount_dir),
("Default Font Path", settings.resolved_default_font_path.parent), # Font directory
]
success = True
for name, path in paths_to_test:
logger.info(f"\nTesting {name}: {path}")
if path.exists():
logger.info(f" β
EXISTS: {path}")
else:
logger.warning(f" β MISSING: {path}")
try:
# Try to create the directory
if name != "Default Font Path": # Don't create font file, just directory
path.mkdir(parents=True, exist_ok=True)
logger.info(f" β
CREATED: {path}")
else:
path.mkdir(parents=True, exist_ok=True)
logger.info(f" β
CREATED FONT DIR: {path}")
except Exception as e:
logger.error(f" β FAILED TO CREATE: {path} - {e}")
success = False
# Check if it's readable/writable
try:
if path.exists():
if path.is_dir():
# Test write access
test_file = path / "test_write.tmp"
test_file.write_text("test")
test_file.unlink()
logger.info(f" β
WRITABLE: {path}")
elif path.is_file():
logger.info(f" β
READABLE: {path}")
except Exception as e:
logger.error(f" β NO WRITE ACCESS: {path} - {e}")
success = False
return success
if __name__ == "__main__":
logger.info("=== PATH CONFIGURATION TEST ===")
success = test_paths()
if success:
logger.info("\nβ
All paths are configured correctly!")
sys.exit(0)
else:
logger.error("\nβ Some paths have issues. Check the logs above.")
sys.exit(1)
except ImportError as e:
print(f"β Failed to import configuration: {e}")
print("Make sure you're running this from the cardserver directory")
sys.exit(1)
except Exception as e:
print(f"β Unexpected error: {e}")
sys.exit(1)
|