30 lines
1.6 KiB
Python
30 lines
1.6 KiB
Python
"""Fetch only the pinned public Articulino assets; no user data or credentials."""
|
|
import argparse,hashlib,json,shutil,sys
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[2]))
|
|
from catalog import remote
|
|
from articulino_runtime import REPO,MODEL_REVISION,ASSETS,verify_assets
|
|
|
|
def download(destination,source=None):
|
|
destination=Path(destination);destination.mkdir(parents=True,exist_ok=True,mode=0o700)
|
|
for item in json.loads(ASSETS.read_text()):
|
|
path=destination/item['file'];path.parent.mkdir(parents=True,exist_ok=True,mode=0o700)
|
|
if path.exists():
|
|
with path.open('rb') as f:digest=hashlib.file_digest(f,'sha256').hexdigest()
|
|
if digest==item['sha256'] and path.stat().st_size==item['bytes']:continue
|
|
raise ValueError('Vorhandene Datei weicht ab: '+item['file'])
|
|
temp=path.with_name(path.name+'.part');h=hashlib.sha256();size=0
|
|
try:
|
|
origin=(Path(source)/item['file']).open('rb') if source else remote('https://huggingface.co/'+REPO+'/resolve/'+MODEL_REVISION+'/'+item['file'])
|
|
with origin as f,temp.open('wb') as out:
|
|
while block:=f.read(1024*1024):
|
|
size+=len(block)
|
|
if size>item['bytes']:raise ValueError('Datei zu groß: '+item['file'])
|
|
out.write(block);h.update(block)
|
|
if size!=item['bytes'] or h.hexdigest()!=item['sha256']:raise ValueError('Prüfsumme abweichend: '+item['file'])
|
|
temp.chmod(0o600);temp.replace(path)
|
|
finally:temp.unlink(missing_ok=True)
|
|
verify_assets(destination)
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('--destination',required=True,type=Path);p.add_argument('--source',type=Path);a=p.parse_args();download(a.destination,a.source)
|