forked from longtao.wu/droboticflow
39 lines
1.7 KiB
Python
39 lines
1.7 KiB
Python
"""Produce explicitly synthetic multi-part examples using the real package entrypoint."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
from backend.operators.builtin.package import operator as package
|
|
from tests.backend.test_delivery_v3_package import NODE, inputs_for
|
|
from tests.backend.test_part_index_package import helpers
|
|
|
|
|
|
def export(destination):
|
|
destination.mkdir(parents=True, exist_ok=True)
|
|
for part in ("part0001", "part0002"):
|
|
work = destination / ("work-" + part)
|
|
work.mkdir()
|
|
inputs = inputs_for(work, [
|
|
{"id": "blank", "description": "", "clipStartMs": 0, "clipEndMs": 500},
|
|
{"id": "invalid", "description": "无效", "isInvalid": True, "clipStartMs": 500, "clipEndMs": 1000},
|
|
])
|
|
inputs[1]["data"]["capture"]["captureId"] = "capture-A/" + part
|
|
inputs[1]["data"]["capture"]["prefix"] = "incoming/capture-A/" + part
|
|
manifest_path = Path(inputs[0]["path"]) / "revision-manifest.json"
|
|
manifest = json.loads(manifest_path.read_text())
|
|
manifest["runId"] = "source-run-" + part
|
|
manifest_path.write_text(json.dumps(manifest))
|
|
inputs[1]["data"]["acceptedMaterializations"][0]["manifestSha256"] = hashlib.sha256(manifest_path.read_bytes()).hexdigest()
|
|
artifacts = package.run("package-" + part, "package", work / "out", NODE, inputs, helpers())
|
|
shutil.copytree(artifacts[0]["path"], destination / part)
|
|
shutil.rmtree(work)
|
|
(destination / "meta_capture-A.json").write_text('{"synthetic":true,"parts":["part0001","part0002"]}\n')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("output", type=Path)
|
|
export(parser.parse_args().output)
|