gh-action-pypi-publish/print-hash.py

27 lines
657 B
Python
Raw Normal View History

import hashlib
import pathlib
import sys
packages_dir = pathlib.Path(sys.argv[1]).resolve().absolute()
2024-05-16 23:24:20 +08:00
print('Showing hash values of files to be uploaded:')
2022-01-08 12:26:32 +08:00
2022-01-09 07:25:56 +08:00
for file_object in packages_dir.iterdir():
2022-01-09 15:18:25 +08:00
sha256 = hashlib.sha256()
2024-05-16 23:23:10 +08:00
md5 = hashlib.md5() # noqa: S324; only use for reference
2022-01-09 15:18:25 +08:00
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
print(file_object)
2024-05-16 23:24:20 +08:00
print('')
content = file_object.read_bytes()
sha256.update(content)
md5.update(content)
blake2_256.update(content)
2024-05-16 23:24:20 +08:00
print(f'SHA256: {sha256.hexdigest()}')
print(f'MD5: {md5.hexdigest()}')
print(f'BLAKE2-256: {blake2_256.hexdigest()}')
print('')