"""Select missing necessary exact text from the already pinned Git trees only.""" import datetime import hashlib import json import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[3] REF = Path(__file__).resolve().parent.parent / "zimage-wash-reference" def main(): rows = json.loads((REF / "sources.json").read_bytes())["sources"] for key, files in { "aux": [ "LICENSE.txt", "utils.py", "src/custom_controlnet_aux/depth_anything/__init__.py", "src/custom_controlnet_aux/util.py", "src/custom_controlnet_aux/depth_anything/transformers.py", ], "easy": [ "py/config.py", "web_version/v1/js/easy/easyWidgets.js", "web_version/v2/easyuse.js", ], }.items(): origin = next(e for e in rows if e["id"] == key) cache = ROOT / ".local-evidence" / ("zimage-wash-" + key + "-git") entries = json.loads((REF / (key + "-tree.json")).read_bytes())["tree"] for file in files: if any(e["id"] == key and e["file"] == file for e in rows): continue ent = next(e for e in entries if e["path"] == file) data = subprocess.check_output( ["git", "-C", str(cache), "show", origin["commit"] + ":" + file] ) name = key + "__" + file.replace("/", "__") (REF / name).write_bytes(data) rows.append( dict( origin, file=file, local_file=name, sha256=hashlib.sha256(data).hexdigest(), git_blob_sha1=ent["sha"], url=f"https://raw.githubusercontent.com/{origin['repo']}/{origin['commit']}/{file}", acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(), ) ) for e in rows: if e["id"] == "aux": e["license_file"] = "aux__LICENSE.txt" elif not e["license_file"].startswith("未知") and not (REF / e["license_file"]).exists(): e["license_file"] = "未知:准确树必要文本缺许可,不推定授权" (REF / "sources.json").write_text( json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n" ) print("PASS necessary text only", len(rows), "sources; no archive or assets") if __name__ == "__main__": main()