File size: 961 Bytes
c0567cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Standard-library SHA-256 integrity check for the provided real VCC files.
import hashlib, os, sys

def sha256_file(path):
    h = hashlib.sha256()
    with open(path, 'rb') as fh:
        for chunk in iter(lambda: fh.read(1 << 20), b''):
            h.update(chunk)
    return h.hexdigest()

def main():
    base = sys.argv[1] if len(sys.argv) > 1 else 'data'
    sums = os.path.join(base, 'SHA256SUMS')
    bad = 0
    with open(sums) as fh:
        for line in fh:
            parts = line.split()
            if len(parts) != 2:
                continue
            want, name = parts
            got = sha256_file(os.path.join(base, name))
            if got != want:
                print('CHECKSUM MISMATCH ' + name)
                bad += 1
            else:
                print('OK ' + name + ' ' + got[:12])
    if bad:
        print('DATA INTEGRITY FAILED')
        sys.exit(1)
    print('ALL CHECKSUMS OK')

if __name__ == '__main__':
    main()