Added logging for GPIO
Python CI / test (3.12) (push) Has been cancelled
Python CI / test (3.13) (push) Has been cancelled

This commit is contained in:
2025-11-23 14:24:23 +01:00
parent a1775baa76
commit 25b20fdbbd
4 changed files with 163 additions and 15 deletions
+34 -1
View File
@@ -10,6 +10,8 @@ Handles:
from __future__ import annotations
import os
import time
import logging
from pathlib import Path
from typing import List, Dict, Optional, Tuple
from PIL import Image, ImageDraw
@@ -29,6 +31,8 @@ from pyWebLayout.core.query import QueryResult
from .book_utils import scan_book_directory, extract_book_metadata
from .state import LibraryState
logger = logging.getLogger(__name__)
class LibraryManager:
"""
@@ -100,19 +104,34 @@ class LibraryManager:
Returns:
List of book dictionaries with metadata
"""
start_time = time.time()
logger.info(f"[LIBRARY] Scanning library: {self.library_path}")
print(f"Scanning library: {self.library_path}")
if not self.library_path.exists():
logger.error(f"Library path does not exist: {self.library_path}")
print(f"Library path does not exist: {self.library_path}")
return []
# Scan directory
scan_start = time.time()
self.books = scan_book_directory(self.library_path)
scan_elapsed = time.time() - scan_start
logger.info(f"[LIBRARY] Directory scan completed in {scan_elapsed:.2f}s - found {len(self.books)} books")
# Cache covers to disk if not already cached
for book in self.books:
cache_start = time.time()
for i, book in enumerate(self.books, 1):
book_start = time.time()
self._cache_book_cover(book)
book_elapsed = time.time() - book_start
if book_elapsed > 0.1: # Only log if caching took significant time
logger.info(f"[LIBRARY] Cached cover {i}/{len(self.books)}: {book['title']} ({book_elapsed:.2f}s)")
cache_elapsed = time.time() - cache_start
logger.info(f"[LIBRARY] Cover caching completed in {cache_elapsed:.2f}s")
total_elapsed = time.time() - start_time
logger.info(f"[LIBRARY] Library scan complete: {len(self.books)} books in {total_elapsed:.2f}s")
print(f"Found {len(self.books)} books in library")
return self.books
@@ -310,15 +329,20 @@ class LibraryManager:
Returns:
PIL Image of the rendered library
"""
start_time = time.time()
if table is None:
if self.library_table is None:
print("No table to render, creating one first...")
logger.info("[LIBRARY] Creating library table...")
self.create_library_table()
table = self.library_table
print("Rendering library table...")
logger.info("[LIBRARY] Rendering library table...")
# Create page
page_start = time.time()
page_style = PageStyle(
border_width=0,
padding=(30, 30, 30, 30),
@@ -328,6 +352,8 @@ class LibraryManager:
page = Page(size=self.page_size, style=page_style)
canvas = page.render()
draw = ImageDraw.Draw(canvas)
page_elapsed = time.time() - page_start
logger.info(f"[LIBRARY] Page creation took {page_elapsed:.2f}s")
# Table style
table_style = TableStyle(
@@ -344,6 +370,8 @@ class LibraryManager:
table_width = page.size[0] - page_style.padding[1] - page_style.padding[3]
# Render table with canvas support for images
render_start = time.time()
logger.info("[LIBRARY] Starting table render (this may load fonts)...")
self.table_renderer = TableRenderer(
table,
table_origin,
@@ -353,10 +381,15 @@ class LibraryManager:
canvas # Pass canvas to enable image rendering
)
self.table_renderer.render()
render_elapsed = time.time() - render_start
logger.info(f"[LIBRARY] Table rendering took {render_elapsed:.2f}s")
# Store rendered page for query support
self.rendered_page = page
total_elapsed = time.time() - start_time
logger.info(f"[LIBRARY] Total render time: {total_elapsed:.2f}s")
return canvas
def handle_library_tap(self, x: int, y: int) -> Optional[str]: