''s
This commit is contained in:
47
verify_offline_bundle.py
Normal file
47
verify_offline_bundle.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
MANIFEST = ROOT / "offline" / "manifest.json"
|
||||
|
||||
|
||||
def digest(path, algorithm):
|
||||
hasher = hashlib.new(algorithm)
|
||||
with path.open("rb") as handle:
|
||||
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
||||
hasher.update(chunk)
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
||||
failures = []
|
||||
for entry in manifest["artifacts"]:
|
||||
path = ROOT / entry["relative_path"]
|
||||
if not path.is_file():
|
||||
failures.append("{} missing".format(entry["relative_path"]))
|
||||
continue
|
||||
if path.stat().st_size != entry["size"]:
|
||||
failures.append("{} size mismatch".format(entry["relative_path"]))
|
||||
continue
|
||||
sha256 = digest(path, "sha256")
|
||||
if sha256 != entry["sha256"]:
|
||||
failures.append("{} sha256 mismatch".format(entry["relative_path"]))
|
||||
continue
|
||||
print("OK {}".format(entry["relative_path"]))
|
||||
|
||||
if failures:
|
||||
for item in failures:
|
||||
print("FAIL {}".format(item))
|
||||
sys.exit(1)
|
||||
|
||||
print("Offline bundle is complete.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user