File size: 867 Bytes
f8a1702
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Verify every published entity against the release SHA256SUMS."""
import argparse
import hashlib
from pathlib import Path

def verify(root):
    root=Path(root).resolve(); count=0
    for row in (root/'SHA256SUMS').read_text().splitlines():
        digest,name=row.split('  ',1); path=(root/name).resolve()
        if root not in path.parents: raise ValueError('Invalid manifest path')
        h=hashlib.sha256()
        with path.open('rb') as f:
            for block in iter(lambda:f.read(1048576),b''): h.update(block)
        if h.hexdigest()!=digest: raise RuntimeError(f'Checksum mismatch: {name}')
        count+=1
    print(f'PASS: {count} published files verified')
    return count

if __name__=='__main__':
    p=argparse.ArgumentParser(); p.add_argument('--bundle-dir',default=Path(__file__).resolve().parents[1])
    verify(p.parse_args().bundle_dir)