Skip to content

Commit

Permalink
add python script to check reproducibility
Browse files Browse the repository at this point in the history
  • Loading branch information
odudex committed Sep 24, 2024
1 parent f2b5c09 commit 5cfc567
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions reproducibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import hashlib


def release_folder():
"""Returns release folder specified on pyproject.toml"""
version = ""
with open("pyproject.toml", "r") as project_file:
lines = project_file.readlines()
for line in lines:
if line.startswith("version"):
version = line.split('"')[-2]
release_folder_name = "krux-v" + version
print("Hashing binaries for:", release_folder_name)
return release_folder_name


def calculate_sha256(file_path):
"""Calculate the SHA-256 hash of a file."""
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()


def find_bin_files(root_dir, extension=".bin"):
"""Find .bin files in root directory and its subdirectories."""
print(f"\nDevice: SHA256 of {extension} file")
for dirpath, _, filenames in os.walk(root_dir):
for filename in filenames:
if filename.endswith(extension):
file_path = os.path.join(dirpath, filename)
sha256_hash = calculate_sha256(file_path)
device_name = dirpath.split("/")[-1].split("_")[-1]
print(f"{device_name}: {sha256_hash}")


if __name__ == "__main__":
root_directory = release_folder()
find_bin_files(root_directory, extension=".bin")
find_bin_files(root_directory, extension=".kfpkg")

0 comments on commit 5cfc567

Please sign in to comment.