39 lines
4.1 KiB
Plaintext
39 lines
4.1 KiB
Plaintext
from pathlib import Path
|
|
import json,hashlib,subprocess,datetime,os,concurrent.futures
|
|
R=Path.cwd();REF=R/'docs/hel-892/krea-views-reference';now=datetime.datetime.now(datetime.timezone.utc).isoformat()
|
|
def git(cache,*args):return subprocess.check_output(['git','-C',str(cache),*args],timeout=60)
|
|
def fetch(spec):
|
|
key,repo,rev,files=spec;cache=R/('.local-evidence/krea-views-'+key+'-git');subprocess.run(['git','init','--bare',str(cache)],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
|
p=subprocess.run(['git','-C',str(cache),'fetch','--filter=blob:none','--depth=1','https://github.com/'+repo+'.git',rev],capture_output=True,timeout=60)
|
|
(REF/(key+'-fetch.txt')).write_bytes(p.stdout+p.stderr);assert p.returncode==0,p.stderr
|
|
commit=git(cache,'rev-parse','FETCH_HEAD^{commit}').decode().strip();obj=git(cache,'rev-parse','FETCH_HEAD').decode().strip();tree=git(cache,'rev-parse',commit+'^{tree}').decode().strip()
|
|
raw=git(cache,'cat-file','commit',commit);(REF/(key+'-commit.txt')).write_bytes(raw)
|
|
(REF/(key+'-tag.txt')).write_bytes(git(cache,'cat-file','-p',obj));(REF/(key+'-tag.json')).write_text(json.dumps({'requested':rev,'object':obj,'commit':commit})+'\n')
|
|
items=[]
|
|
for row in git(cache,'ls-tree','-r','-z',commit).split(b'\0'):
|
|
if not row:continue
|
|
meta,path=row.split(b'\t',1);mode,typ,oid=meta.decode().split();items.append({'path':path.decode(),'mode':mode,'type':typ,'sha':oid})
|
|
(REF/(key+'-tree.json')).write_text(json.dumps({'sha':tree,'truncated':False,'tree':items},indent=2)+'\n')
|
|
(REF/(key+'-text-paths.json')).write_text(json.dumps([x['path'] for x in items if x['path'].endswith(('.py','.toml','.txt','.md','.js','.ts'))],indent=2)+'\n')
|
|
results=[]
|
|
for file in files:
|
|
entry=next((e for e in items if e['path']==file),None)
|
|
if not entry:continue
|
|
raw=git(cache,'show',commit+':'+file);assert len(raw)<3000000
|
|
name=key+'__'+file.replace('/','__');(REF/name).write_bytes(raw)
|
|
results.append(dict(id=key,repo=repo,file=file,local_file=name,commit=commit,tree=tree,tag=rev,url=f'https://raw.githubusercontent.com/{repo}/{commit}/{file}',sha256=hashlib.sha256(raw).hexdigest(),git_blob_sha1=entry['sha'],acquisition_time=now,reverified_at=now,license_file=key+'__LICENSE',transport='filtered Git, selected text blobs only',identity_root='.',identity_key=key,applicability='本图准确声明静态参考;不执行上游,不认证目标安装或模型许可'))
|
|
return results
|
|
specs=[('core0270','Comfy-Org/ComfyUI','v0.27.0',['nodes.py','comfy_extras/nodes_primitive.py','comfy_extras/nodes_resolution.py','comfy_extras/nodes_seed.py','LICENSE','requirements.txt']),('core0375','Comfy-Org/ComfyUI','v0.3.75',['nodes.py','folder_paths.py','LICENSE','requirements.txt']),('rebalance','huwhitememes/comfyui-krea2-conditioning','729cda4fade982988a375b01928f515458407a5c',['__init__.py','nodes.py','LICENSE','requirements.txt','pyproject.toml'])]
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:rows=[e for es in pool.map(fetch,specs) for e in es]
|
|
for directory,key,files in [('krea-identity-reference','core0260',{'nodes.py','comfy/samplers.py','LICENSE'}),('krea-realn-reference','frontend',None),('krea-auto-reference','core0250',{'nodes.py','comfy_extras/nodes_string.py','LICENSE','requirements.txt'})]:
|
|
old=R/'docs/hel-892'/directory
|
|
for original in json.loads((old/'sources.json').read_bytes())['sources']:
|
|
if original['id']!=key or (files is not None and original['file'] not in files):continue
|
|
e=dict(original)
|
|
for k in ['local_file','license_file','identity_root']:e[k]=os.path.relpath((old/e[k]).resolve(),REF)
|
|
assert hashlib.sha256((REF/e['local_file']).read_bytes()).hexdigest()==e['sha256']
|
|
e.update(reverified_at=now,reuse_from=directory);rows.append(e)
|
|
(REF/'sources.json').write_text(json.dumps({'sources':rows},ensure_ascii=False,indent=2)+'\n');print('Sources',len(rows))
|
|
|
|
# 后续仅从准确缓存取core0260 requirements.txt和core0270的三个comfy_api/latest接口文本,补齐Seed固定辅助声明;core0250 nodes_string.py复用realn已核字节。最终权威逐字节清单是sources.json;没有发布包、权重、素材或上游执行。
|