26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
"""Restore public artifacts only, pinned by revision and SHA256."""
|
|
import hashlib,json,pathlib,urllib.request
|
|
base=pathlib.Path(__file__).resolve().parent
|
|
root=pathlib.Path('/opt/athena-helper-tts');root.mkdir(exist_ok=True)
|
|
for manifest in ('manifest.json','piper-manifest.json'):
|
|
for row in json.loads((base/manifest).read_text())['files']:
|
|
name=row['path'] if manifest=='manifest.json' else 'models/'+row['path']
|
|
target=root/name;target.parent.mkdir(exist_ok=True)
|
|
def checksum(path):
|
|
h=hashlib.sha256()
|
|
with path.open('rb') as f:
|
|
for block in iter(lambda:f.read(8*1024*1024),b''): h.update(block)
|
|
return h.hexdigest()
|
|
if target.exists():
|
|
if checksum(target)!=row['sha256']:raise RuntimeError('Existing artifact differs: '+name)
|
|
continue
|
|
part=target.with_suffix(target.suffix+'.part')
|
|
with urllib.request.urlopen(row['url'],timeout=120) as r,part.open('wb') as f:
|
|
while True:
|
|
block=r.read(8*1024*1024)
|
|
if not block:break
|
|
f.write(block)
|
|
if checksum(part)!=row['sha256']:raise RuntimeError('Checksum mismatch: '+name)
|
|
part.replace(target)
|
|
(root/'koboldcpp').chmod(0o755)
|