Files
aigc-home/docs/hel-892/animate2-loop-document-evidence/extend-a2loop.py.txt
T

37 lines
4.0 KiB
Plaintext

from pathlib import Path
import json,subprocess,hashlib,datetime,urllib.request,urllib.error,os
R=Path.cwd();F=R/'docs/hel-892/animate2-loop-reference';rows=json.loads((F/'sources.json').read_bytes())['sources']
def utc():return datetime.datetime.now(datetime.timezone.utc).isoformat()
def add(key,repo,path):
root=R/('.local-evidence/a2loop-'+key+'-git');commit=subprocess.check_output(['git','-C',str(root),'rev-parse','FETCH_HEAD^{commit}']).decode().strip();tree=json.loads((F/(key+'-tree.json')).read_bytes());entry=next((e for e in tree['tree']if e['path']==path),None)
if not entry:print('MISSING',key,path);return
raw=subprocess.check_output(['git','-C',str(root),'show',commit+':'+path]);now=utc();name=key+'__'+path.replace('/','__');(F/name).write_bytes(raw);assert hashlib.sha1(b'blob '+str(len(raw)).encode()+b'\0'+raw).hexdigest()==entry['sha']
exemplar=next(e for e in rows if e['id']==key);e=dict(exemplar,file=path,local_file=name,sha256=hashlib.sha256(raw).hexdigest(),git_blob_sha1=entry['sha'],acquisition_time=now,reverified_at=utc(),url=f'https://raw.githubusercontent.com/{repo}/{commit}/{path}');rows.append(e)
for key,path in [('tt','LICENSE.txt'),('frontend','src/lib/litegraph/src/subgraph/NodeInputSlot.ts'),('core0311','comfy_extras/nodes_context_windows.py')]:
if not any(e['id']==key and e['file']==path for e in rows):add(key,'Comfy-Org/ComfyUI_frontend'if key=='frontend'else'AICoderTudou/ComfyUI-TT-Resolution_selector-Node'if key=='tt'else'Comfy-Org/ComfyUI',path)
for path in ['https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/commits/173652f200c49d2908dc1907c187af416b9d6264','https://raw.githubusercontent.com/Kosinkadink/ComfyUI-VideoHelperSuite/173652f200c49d2908dc1907c187af416b9d6264/videohelpersuite/load_video_nodes.py']:
try:
with urllib.request.urlopen(path,timeout=30)as response:raw=response.read();status=response.status
except urllib.error.HTTPError as e:raw=e.read();status=e.code
name='vhs-unavailable-'+str(len([e for e in rows if e['id']=='vhs']))+'.txt';(F/name).write_bytes(raw);now=utc();rows.append(dict(id='vhs',repo='Kosinkadink/ComfyUI-VideoHelperSuite',commit='173652f200c49d2908dc1907c187af416b9d6264',tag='准确完整提交声明',tree='未知:准确提交未取得',file=name,local_file=name,url=path,http_status=status,sha256=hashlib.sha256(raw).hexdigest(),git_blob_sha1='未知:没有准确文本',acquisition_time=now,reverified_at=utc(),license_file='未知:准确提交未取得',identity_root='.',identity_key='vhs',claim='具体提交取源响应,不是实现或全仓无类证明'));print('VHS',status)
# Retain every original acquisition, select earliest known same repo/commit/path/SHA.
prior=[]
for p in (R/'docs/hel-892').glob('*/sources.json'):
if p.parent==F:continue
try:d=json.loads(p.read_bytes());old=d.get('sources',[])if isinstance(d,dict)else d
except (ValueError,AttributeError):continue
for e in old:prior.append((p,e))
changes=[]
for e in rows:
matches=[]
for p,x in prior:
if all(e.get(k)==x.get(k)for k in ['repo','commit','file','sha256']) and x.get('acquisition_time'):
try:t=datetime.datetime.fromisoformat(x['acquisition_time'].replace('Z','+00:00'));assert t.utcoffset()is not None
except (ValueError,AssertionError):continue
matches.append(dict(record=str(p.relative_to(R)),acquisition_time=x['acquisition_time']))
if matches:
current=e.get('acquisition_time');earliest=min([current]+[m['acquisition_time']for m in matches],key=lambda s:datetime.datetime.fromisoformat(s.replace('Z','+00:00')))
e['prior_acquisition_records']=matches;e['current_fetch_at']=current;e['acquisition_time']=earliest;e['acquisition_basis']='最早已知同repo/commit/path/SHA记录;不宣称全球首次';changes.append(dict(id=e['id'],file=e['file'],current_fetch_at=current,earliest_known=earliest,records=matches))
(F/'sources.json').write_text(json.dumps(dict(sources=rows),ensure_ascii=False,indent=2)+'\n');(F/'acquisition-history.json').write_text(json.dumps(changes,ensure_ascii=False,indent=2)+'\n')
print('TOTAL',len(rows))