Files
aigc-home/docs/hel-892/krea-auto-document-evidence/source-acquisition-recipe.txt
T

37 lines
4.2 KiB
Plaintext

from pathlib import Path
import json,hashlib,subprocess,datetime,os,concurrent.futures
R=Path.cwd();REF=R/'docs/hel-892/krea-auto-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-auto-'+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=[('core0280','Comfy-Org/ComfyUI','v0.28.0',['comfy_extras/nodes_string.py','LICENSE','requirements.txt']),('core0342','Comfy-Org/ComfyUI','v0.34.2',['comfy_extras/nodes_primitive.py','comfy_extras/nodes_logic.py','LICENSE','requirements.txt']),('painter','princepainter/ComfyUI-PainterNodes','2864e1542d6e03e4429e919a02cffed081039cfb',['__init__.py','PainterVRAM.py','LICENSE','requirements.txt','pyproject.toml']),('frontend','Comfy-Org/ComfyUI_frontend','v1.45.20',['package.json','pnpm-lock.yaml','pnpm-workspace.yaml','src/scripts/widgets.ts','src/scripts/app.ts','src/lib/litegraph/src/litegraph.ts','src/lib/litegraph/src/LGraphNode.ts','src/lib/litegraph/src/LGraph.ts','src/lib/litegraph/LICENSE','LICENSE','src/core/graph/widgets/dynamicWidgets.ts','src/core/graph/widgets/dynamicTypes.ts','src/lib/litegraph/src/subgraph/SubgraphNode.ts'])]
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool:rows=[e for es in pool.map(fetch,specs) for e in es]
old=R/'docs/hel-892/krea-realn-reference'
for original in json.loads((old/'sources.json').read_bytes())['sources']:
if original['id']!='core0250' or original['file'] not in ['nodes.py','folder_paths.py','comfy_extras/nodes_primitive.py','comfy_extras/nodes_resolution.py','comfy/samplers.py','LICENSE']:continue
e=dict(original)
for key in ['local_file','license_file','identity_root']:e[key]=os.path.relpath((old/e[key]).resolve(),REF)
e.update(reverified_at=now,reuse_from='exact existing bytes');rows.append(e)
(REF/'sources.json').write_text(json.dumps({'sources':rows},ensure_ascii=False,indent=2)+'\n');print('Sources',len(rows))
# ShowText仅调用本目录fetch_release.py,准确1.2.5 Range必要成员;完整包摘要/Git绑定未知。LLM精确fetch/raw仍拒绝,记录在llama-unavailable.json及prior原记录。core0250 requirements复用上批准确已核字节,来源/时间见最终sources.json。