From e94962ccbb910be55fa398802f0e28b945fd7c57 Mon Sep 17 00:00:00 2001 From: Philip Zimmermann Date: Sat, 13 Dec 2025 18:26:56 +0100 Subject: [PATCH] Fixed dev environment database setup --- Dockerfile | 6 ++++-- aperisolve/analyzers/image_resize.py | 5 +++-- aperisolve/analyzers/utils.py | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5487996..fc2198a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,10 @@ RUN apt-get update && apt-get install -y \ COPY aperisolve/ /aperisolve/ +RUN mkdir -p /data + RUN pip install --no-cache-dir -r /aperisolve/requirements.txt -RUN PYTHONPATH=/ python -c "from aperisolve.utils import create_crc_db; create_crc_db()" +RUN PYTHONPATH=/ python -c "from aperisolve.analyzers.utils import create_crc_db; create_crc_db()" -CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "aperisolve.wsgi:application"] \ No newline at end of file +CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "aperisolve.wsgi:application"] diff --git a/aperisolve/analyzers/image_resize.py b/aperisolve/analyzers/image_resize.py index 45a6194..66a62c7 100644 --- a/aperisolve/analyzers/image_resize.py +++ b/aperisolve/analyzers/image_resize.py @@ -4,7 +4,8 @@ import zlib import sqlite3 from pathlib import Path from typing import List -from .utils import update_data +from .utils import update_data, DB_PATH + # Full list of expected sizes EXPECTED_SIZES = [ @@ -188,7 +189,7 @@ def lookup_crc(crc_bytes: bytes, logs: List[str]) -> List[tuple[int, int]]: Queries the SQLite DB for the CRC and returns a list of (width, height) tuples. """ # Locate DB relative to this script file - db_path = Path(__file__).parent / "ihdr_crcs.db" + db_path = Path(DB_PATH) if not db_path.exists(): logs.append(f"Error: Database not found at {db_path}") diff --git a/aperisolve/analyzers/utils.py b/aperisolve/analyzers/utils.py index 55fdbaa..c539abd 100644 --- a/aperisolve/analyzers/utils.py +++ b/aperisolve/analyzers/utils.py @@ -64,10 +64,12 @@ def create_crc_db() -> None: if os.path.exists(DB_PATH): print(f"Database already exists at {DB_PATH}. Skipping generation.") return - db_filename = "ihdr_crcs.db" - # Connect to database - conn = sqlite3.connect(db_filename) + # Use the global DB_PATH variable so it writes to /data/ in Docker + # and /analyzers/ in local dev + print(f"Generating database at: {DB_PATH}") + conn = sqlite3.connect(DB_PATH) + cursor = conn.cursor() # Optimization: Turn off safety checks for bulk insertion speed