"""Check the source archive's file inventory and SHA-256 hashes (stdlib only).""" from hashlib import sha256 import json from pathlib import Path import sys def main(): here = Path(__file__).resolve().parent manifest_path = here / 'package-manifest.json' if not manifest_path.is_file(): raise SystemExit('Run this checker from the anc directory of the extracted source archive.') root = here.parent manifest = json.loads(manifest_path.read_text(encoding='utf-8')) failures = [] for row in manifest['files']: path = root / row['path'] if not path.is_file(): failures.append('missing: ' + row['path']) elif sha256(path.read_bytes()).hexdigest() != row['sha256']: failures.append('changed: ' + row['path']) if failures: print('\n'.join(failures)) return 1 print('PASS: %d source and verification files match the package manifest.' % len(manifest['files'])) return 0 if __name__ == '__main__': sys.exit(main())