105 lines
3.8 KiB
Python
105 lines
3.8 KiB
Python
"""Range-read exact release necessary text only; never install or import upstream."""
|
|
|
|
import datetime
|
|
import hashlib
|
|
import io
|
|
import json
|
|
import urllib.request
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
REF = Path(__file__).resolve().parent.parent / "zimage-outpaint-reference"
|
|
|
|
|
|
class Remote(io.RawIOBase):
|
|
def __init__(self, url):
|
|
self.url = url
|
|
self.pos = 0
|
|
self.log = []
|
|
with urllib.request.urlopen(urllib.request.Request(url, method="HEAD"), timeout=30) as r:
|
|
self.size = int(r.headers["Content-Length"])
|
|
self.headers = dict(r.headers)
|
|
|
|
def seekable(self):
|
|
return True
|
|
|
|
def readable(self):
|
|
return True
|
|
|
|
def tell(self):
|
|
return self.pos
|
|
|
|
def seek(self, off, whence=0):
|
|
self.pos = off if whence == 0 else self.pos + off if whence == 1 else self.size + off
|
|
return self.pos
|
|
|
|
def read(self, n=-1):
|
|
n = min(self.size - self.pos, n if n >= 0 else self.size - self.pos)
|
|
if n <= 0:
|
|
return b""
|
|
a = self.pos
|
|
b = a + n - 1
|
|
req = urllib.request.Request(self.url, headers={"Range": f"bytes={a}-{b}"})
|
|
with urllib.request.urlopen(req, timeout=40) as r:
|
|
assert r.status == 206 and r.headers["Content-Range"].startswith(f"bytes {a}-{b}/")
|
|
raw = r.read(n + 1)
|
|
assert len(raw) == n
|
|
self.pos += n
|
|
self.log.append(dict(start=a, end=b, sha256=hashlib.sha256(raw).hexdigest()))
|
|
return raw
|
|
|
|
|
|
def main():
|
|
url = "https://api.comfy.org/nodes/seedvr2_videoupscaler/versions/2.5.22"
|
|
with urllib.request.urlopen(url, timeout=30) as r:
|
|
raw = r.read()
|
|
(REF / "seedpkg-registry.json").write_bytes(raw)
|
|
meta = json.loads(raw)
|
|
print(meta.keys(), flush=True)
|
|
download = meta["downloadUrl"] if "downloadUrl" in meta else meta["download_url"]
|
|
archive = Remote(download)
|
|
acquisition = json.loads((REF / "seedpkg-acquisition.json").read_bytes())
|
|
rows = []
|
|
members = []
|
|
with zipfile.ZipFile(archive) as z:
|
|
for info in z.infolist():
|
|
members.append(dict(name=info.filename, size=info.file_size, crc=info.CRC))
|
|
f = info.filename
|
|
if not (
|
|
f in ["__init__.py", "LICENSE", "LICENSE.txt", "pyproject.toml"]
|
|
or (f.endswith(".py") and ("interface" in f or "schema" in f or "node" in f))
|
|
):
|
|
continue
|
|
data = z.read(f)
|
|
name = "seedpkg__" + f.replace("/", "__")
|
|
(REF / name).write_bytes(data)
|
|
rows.append(
|
|
dict(
|
|
id="seedpkg",
|
|
file=f,
|
|
local_file=name,
|
|
tag="2.5.22",
|
|
commit="发布包到Git绑定未知",
|
|
tree="发布包;Git tree未知",
|
|
url=download,
|
|
sha256=hashlib.sha256(data).hexdigest(),
|
|
package_sha256=acquisition["archive_sha256"],
|
|
member_crc32=info.CRC,
|
|
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
license_file="seedpkg__LICENSE",
|
|
identity_root=".",
|
|
identity_key="seedpkg",
|
|
applicability="本图710独立准确发布身份,整包SHA/成员CRC与Git未知绑定分列",
|
|
)
|
|
)
|
|
(REF / "seedpkg-members.json").write_text(json.dumps(members, indent=2) + "\n")
|
|
(REF / "seedpkg-sources.json").write_text(
|
|
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
(REF / "seedpkg-range-proof.json").write_text(json.dumps(archive.log, indent=2) + "\n")
|
|
print("PASS exact release Range", len(rows), "necessary text members")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|