Files
aigc-home/docs/hel-892/flux2-action-document-evidence/fetch_sources.py
T

135 lines
4.8 KiB
Python

"Acquire necessary pinned text only; no upstream imports or execution."
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 / "flux2-action-reference"
def main():
rows = []
specs = [
(
"comparer",
"aining2022/ComfyUI_Swwan",
"881bc91790da6b907d3d28e5b91b295b9aef06ee",
["image_comparer.py", "web/js/image_comparer.js", "__init__.py", "LICENSE"],
),
(
"core",
"Comfy-Org/ComfyUI",
"v0.9.2",
["nodes.py", "node_helpers.py", "comfy/utils.py", "comfy_api/latest/_io.py", "LICENSE"],
),
(
"dw",
"Fannovel16/comfyui_controlnet_aux",
"cc6b232f4a47f0cdf70f4e1bfa24b74bd0d75bf1",
[
"node_wrappers/dwpose.py",
"src/custom_controlnet_aux/dwpose/__init__.py",
"src/custom_controlnet_aux/util.py",
"utils.py",
"__init__.py",
"LICENSE.txt",
"src/custom_controlnet_aux/dwpose/LICENSE",
],
),
(
"painter",
"princepainter/ComfyUI-PainterNodes",
"88af927351c1f16f913104fc7aec3bb880baa2df",
["PainterFluxImageEdit.py", "__init__.py", "LICENSE"],
),
(
"easy",
"yolain/ComfyUI-Easy-Use",
"v1.3.6",
["py/nodes/image.py", "py/libs/utils.py", "__init__.py", "LICENSE"],
),
]
for key, repo, tag, files in specs:
cache = ROOT / ".local-evidence" / ("flux2-action-" + key + "-git")
cache.mkdir(parents=True, exist_ok=True)
subprocess.run(["git", "init", "--bare", str(cache)], check=True, stdout=subprocess.DEVNULL)
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=("refs/tags/" + tag) if tag.startswith("v") else 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 = []
for f in 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.txt" if key == "dw" else "__LICENSE"),
transport="filtered git; selected text blobs only",
applicability="本图独立声明版本;UE/tab/宿主恢复未知",
)
)
(REF / (key + "-absent.json")).write_text(json.dumps(missing, indent=2) + "\n")
(REF / "new-sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()