3b9d1ef1a8
- Replace the Docker build/publish CI stages with ruff (lint + format check), ty (type check), pip-audit, and pytest run directly against python:3.11-slim; Docker remains for manual/server deployment only. - Swap black/pylint/mypy for ruff/ty across pyproject.toml, and fix every resulting lint, format, and type diagnostic in gallery/ and plotstyle/. - Fix tests broken/stale from before the package restructuring: wrong `utils.*` import paths, mock patch targets pointed at the wrong module, and PDF-conversion tests still assuming ImageMagick instead of the current PyMuPDF-first path. Drop test_container.py (obsolete Docker-container smoke tests, fully superseded elsewhere). - Add a plain-venv + systemd --user timer deployment path (deploy/systemd/) for HPC login nodes without a Docker daemon, where public_html is already served by existing infrastructure. - Document both in CLAUDE.md, including running CI's checks locally before committing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
"""Statistics calculation for gallery directories."""
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
def calculate_directory_stats(directory: Path) -> dict:
|
|
"""
|
|
Calculate statistics for a directory.
|
|
|
|
Args:
|
|
directory: Path to the directory to analyze
|
|
|
|
Returns:
|
|
Dictionary containing file count, folder count, and total size
|
|
"""
|
|
stats = {
|
|
"file_count": 0,
|
|
"folder_count": 0,
|
|
"total_size": 0,
|
|
"pdf_size": 0,
|
|
"png_size": 0,
|
|
}
|
|
|
|
if not directory.exists():
|
|
return stats
|
|
|
|
for item in directory.rglob("*"):
|
|
if item.is_file():
|
|
stats["file_count"] += 1
|
|
size = item.stat().st_size
|
|
stats["total_size"] += size
|
|
|
|
if item.suffix.lower() == ".pdf":
|
|
stats["pdf_size"] += size
|
|
elif item.suffix.lower() == ".png":
|
|
stats["png_size"] += size
|
|
elif item.is_dir():
|
|
stats["folder_count"] += 1
|
|
|
|
return stats
|
|
|
|
|
|
def format_file_size(size_bytes: int) -> str:
|
|
"""
|
|
Format file size in human readable format.
|
|
|
|
Args:
|
|
size_bytes: Size in bytes
|
|
|
|
Returns:
|
|
Formatted size string
|
|
"""
|
|
if size_bytes == 0:
|
|
return "0 B"
|
|
|
|
size_names = ["B", "KB", "MB", "GB", "TB"]
|
|
size = float(size_bytes)
|
|
i = 0
|
|
while size >= 1024 and i < len(size_names) - 1:
|
|
size /= 1024
|
|
i += 1
|
|
|
|
return f"{size:.1f} {size_names[i]}"
|