File size: 1,072 Bytes
29439fe | 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 | #!/usr/bin/env python3
"""Stream-check every file listed in a complete TTS-V4 delivery."""
import argparse
import hashlib
from pathlib import Path
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--directory',type=Path,default=Path(__file__).resolve().parent)
args=parser.parse_args()
root=args.directory.resolve()
manifest=root/'SHA256SUMS'
checked=0
for line in manifest.read_text().splitlines():
expected,name=line.split(' ',1)
path=(root/name).resolve()
if not path.is_relative_to(root) or not path.is_file():
raise SystemExit(f'缺少文件或非法路径:{name}')
digest=hashlib.sha256()
with path.open('rb') as handle:
for block in iter(lambda:handle.read(8*1024*1024),b''):
digest.update(block)
if digest.hexdigest()!=expected:
raise SystemExit(f'校验失败:{name}')
checked+=1
print(f'全部{checked}个文件SHA-256校验通过:{root}')
if __name__=='__main__':
main()
|