183 lines
6.6 KiB
Python
183 lines
6.6 KiB
Python
"""Reuse exact necessary bytes, then acquire bounded missing pinned source text only."""
|
|
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
REF = OUT.parent / "zimage-seed8k-reference"
|
|
REF.mkdir(exist_ok=True)
|
|
|
|
SPECS = [
|
|
("core040", "Comfy-Org/ComfyUI", "v0.4.0", ["nodes.py", "LICENSE"]),
|
|
(
|
|
"core0270",
|
|
"Comfy-Org/ComfyUI",
|
|
"v0.27.0",
|
|
[
|
|
"nodes.py",
|
|
"comfy_extras/nodes_seedvr.py",
|
|
"comfy_extras/nodes_images.py",
|
|
"comfy_extras/nodes_compositing.py",
|
|
"LICENSE",
|
|
],
|
|
),
|
|
(
|
|
"layer",
|
|
"chflame163/ComfyUI_LayerStyle",
|
|
"4f4d5cbbe40e030a5a0bb474fb65c4032585bc3c",
|
|
["__init__.py", "py/purge_vram.py", "py/imagefunc.py", "LICENSE"],
|
|
),
|
|
(
|
|
"rgthree",
|
|
"rgthree/rgthree-comfy",
|
|
"b775441a4c5ae2853d4ff6b97a137f7f7d11e597",
|
|
[
|
|
"__init__.py",
|
|
"py/image_comparer.py",
|
|
"py/utils.py",
|
|
"web/comfyui/image_comparer.js",
|
|
"LICENSE",
|
|
],
|
|
),
|
|
]
|
|
|
|
|
|
def main():
|
|
rows = []
|
|
selections = [
|
|
("zimage-hd-reference", {"frontend": "frontend", "litegraph": "litegraph", "cr": "cr"}),
|
|
("zimage-wash-reference", {"core051": "core051"}),
|
|
]
|
|
for folder, ids in selections:
|
|
root = REF.parent / folder
|
|
for original in json.loads((root / "sources.json").read_bytes())["sources"]:
|
|
if original["id"] not in ids:
|
|
continue
|
|
e = original.copy()
|
|
e["identity_key"] = e.get("identity_key", e["id"])
|
|
e["id"] = ids[original["id"]]
|
|
if any(x["id"] == e["id"] and x["file"] == e["file"] for x in rows):
|
|
continue
|
|
for keyname in ["local_file", "identity_root"]:
|
|
e[keyname] = "../" + folder + "/" + e.get(keyname, ".")
|
|
if not e["license_file"].startswith("未知"):
|
|
e["license_file"] = "../" + folder + "/" + e["license_file"]
|
|
e.setdefault("tag", e["commit"])
|
|
e["applicability"] = (
|
|
"本图独立准确声明身份;旧采集时间保留、原字节重核。包到Git未知、宿主和别名恢复未知。"
|
|
)
|
|
rows.append(e)
|
|
for key, repo, tag, files in SPECS:
|
|
cache = ROOT / ".local-evidence" / ("zimage-seed8k-" + key + "-git")
|
|
cache.mkdir(parents=True, exist_ok=True)
|
|
subprocess.run(["git", "init", "--bare", str(cache)], check=True, stdout=subprocess.DEVNULL)
|
|
if not (cache / "FETCH_HEAD").exists():
|
|
subprocess.run(
|
|
[
|
|
"git",
|
|
"-C",
|
|
str(cache),
|
|
"fetch",
|
|
"--filter=blob:none",
|
|
"--depth=1",
|
|
"https://github.com/" + repo + ".git",
|
|
("refs/tags/" + tag) if tag.startswith("v") else tag,
|
|
],
|
|
check=True,
|
|
)
|
|
|
|
def git(*args):
|
|
return subprocess.check_output(["git", "-C", str(cache), *args])
|
|
|
|
rev = git("rev-parse", "FETCH_HEAD^{commit}").decode().strip()
|
|
tree = git("rev-parse", rev + "^{tree}").decode().strip()
|
|
(REF / (key + "-commit.txt")).write_bytes(git("cat-file", "commit", rev))
|
|
(REF / (key + "-tag.txt")).write_bytes(git("cat-file", "-p", "FETCH_HEAD"))
|
|
(REF / (key + "-tag.json")).write_text(
|
|
json.dumps(
|
|
dict(
|
|
ref=tag,
|
|
commit=rev,
|
|
object=git("rev-parse", "FETCH_HEAD").decode().strip(),
|
|
),
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
entries = []
|
|
for line in git("ls-tree", "-r", rev).decode().splitlines():
|
|
head, path = line.split("\t", 1)
|
|
mode, kind, sha = head.split()
|
|
entries.append(dict(path=path, mode=mode, type=kind, sha=sha))
|
|
(REF / (key + "-tree.json")).write_text(
|
|
json.dumps(dict(sha=tree, truncated=False, tree=entries), indent=2) + "\n"
|
|
)
|
|
missing = []
|
|
# Discover exact source text names within accurate tree, bounded to relevant classes/files.
|
|
if key in ["easy", "reel", "core0270", "layer"]:
|
|
files += [
|
|
e["path"]
|
|
for e in entries
|
|
if e["path"].endswith(".py")
|
|
and any(
|
|
s in e["path"].lower()
|
|
for s in (
|
|
["seedvr", "resize"]
|
|
if key == "core0270"
|
|
else ["purge"]
|
|
if key == "layer"
|
|
else ["seed", "reel"]
|
|
)
|
|
)
|
|
]
|
|
if key == "easy":
|
|
files += [
|
|
e["path"]
|
|
for e in entries
|
|
if e["path"].endswith(".js") and "seed" in e["path"].lower()
|
|
]
|
|
for f in dict.fromkeys(files):
|
|
ent = next((x for x in entries if x["path"] == f), None)
|
|
if ent is None:
|
|
missing.append(f)
|
|
continue
|
|
raw = git("show", rev + ":" + f)
|
|
name = key + "__" + f.replace("/", "__")
|
|
(REF / name).write_bytes(raw)
|
|
rows.append(
|
|
dict(
|
|
id=key,
|
|
repo=repo,
|
|
file=f,
|
|
local_file=name,
|
|
commit=rev,
|
|
tree=tree,
|
|
tag=tag,
|
|
url=f"https://raw.githubusercontent.com/{repo}/{rev}/{f}",
|
|
sha256=hashlib.sha256(raw).hexdigest(),
|
|
git_blob_sha1=ent["sha"],
|
|
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
license_file=key + "__LICENSE",
|
|
transport="filtered git; selected text only",
|
|
applicability="本图准确声明版本静态参考;不执行上游或认证目标环境",
|
|
identity_root=".",
|
|
identity_key=key,
|
|
)
|
|
)
|
|
(REF / (key + "-absent.json")).write_text(json.dumps(missing, indent=2) + "\n")
|
|
for e in rows:
|
|
if e["id"] == "core0211":
|
|
e["identity_root"] = "../flux2-img-reference"
|
|
(REF / "sources.json").write_text(
|
|
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print("PINNED", key, rev, flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|