Initial Commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
jobs.py — Build and serialise the jobs.json payload passed to process.py.
|
||||
|
||||
The jobs file is the sole interface between the GUI/host Python environment
|
||||
and the Nuke Python environment. Keeping it as plain JSON means process.py
|
||||
has no dependency on this project's other modules.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from parser import Shot
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
# Public API
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
def build_jobs_payload(shots: list[Shot], template_script: str) -> dict:
|
||||
"""Return the dict that will be serialised to jobs.json.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
shots:
|
||||
Shots selected for rendering.
|
||||
template_script:
|
||||
Absolute path to the Nuke template (.nk) file.
|
||||
"""
|
||||
return {
|
||||
"template_script": Path(template_script).as_posix(),
|
||||
"jobs": [_shot_to_job(s) for s in shots],
|
||||
}
|
||||
|
||||
|
||||
def write_jobs_file(payload: dict, path: str) -> None:
|
||||
"""Write *payload* to *path* as indented JSON."""
|
||||
with open(path, "w", encoding="utf-8") as fh:
|
||||
json.dump(payload, fh, indent=2)
|
||||
|
||||
|
||||
def read_jobs_file(path: str) -> dict:
|
||||
"""Read and return the jobs payload from *path*."""
|
||||
with open(path, encoding="utf-8") as fh:
|
||||
return json.load(fh)
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
# Internal helpers
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
def _shot_to_job(shot: Shot) -> dict:
|
||||
return {
|
||||
"basename": shot.basename,
|
||||
"input_sequence": shot.input_sequence,
|
||||
"first_frame": shot.first_frame,
|
||||
"last_frame": shot.last_frame,
|
||||
"output_folder": shot.output_folder,
|
||||
"output_movie": shot.output_movie,
|
||||
"output_exr": shot.output_exr,
|
||||
}
|
||||
Reference in New Issue
Block a user