Update image manifest (1 image)
This commit is contained in:
1 parent
a28201bdf6
commit
af59ab4a9d
2 files changed
+20
-3
No files matched your search
Binary file not shown.
+20
-3
@@ -67,15 +67,31 @@ def find_images() -> list[dict]:
|
|||||||
return images
|
return images
|
||||||
|
|
||||||
|
|
||||||
def write_manifest(images: list[dict]) -> None:
|
def write_manifest(images: list[dict]) -> bool:
|
||||||
|
"""Write images.json. Returns True if the file changed.
|
||||||
|
|
||||||
|
If the image list is identical to what's already on disk, the file is left
|
||||||
|
untouched (keeping its timestamp) so a no-op run produces no commit.
|
||||||
|
"""
|
||||||
|
plural = "" if len(images) == 1 else "s"
|
||||||
|
|
||||||
|
if OUT_FILE.exists():
|
||||||
|
try:
|
||||||
|
existing = json.loads(OUT_FILE.read_text(encoding="utf-8"))
|
||||||
|
except (json.JSONDecodeError, OSError):
|
||||||
|
existing = None
|
||||||
|
if isinstance(existing, dict) and existing.get("images") == images:
|
||||||
|
print(f"• Manifest unchanged ({len(images)} image{plural}).")
|
||||||
|
return False
|
||||||
|
|
||||||
manifest = {
|
manifest = {
|
||||||
"generatedAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
|
"generatedAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
|
||||||
"count": len(images),
|
"count": len(images),
|
||||||
"images": images,
|
"images": images,
|
||||||
}
|
}
|
||||||
OUT_FILE.write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
OUT_FILE.write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
||||||
plural = "" if len(images) == 1 else "s"
|
|
||||||
print(f"✓ Wrote {len(images)} image{plural} to {OUT_FILE.name}")
|
print(f"✓ Wrote {len(images)} image{plural} to {OUT_FILE.name}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def git(*args: str, check: bool = True) -> subprocess.CompletedProcess:
|
def git(*args: str, check: bool = True) -> subprocess.CompletedProcess:
|
||||||
@@ -117,7 +133,8 @@ def main() -> None:
|
|||||||
if args.no_commit:
|
if args.no_commit:
|
||||||
return
|
return
|
||||||
|
|
||||||
message = args.message or f"Update image manifest ({len(images)} images)"
|
plural = "" if len(images) == 1 else "s"
|
||||||
|
message = args.message or f"Update image manifest ({len(images)} image{plural})"
|
||||||
commit(message)
|
commit(message)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user