Utility script to help create sha256 hashes 93/47193/2
authorlhinds <lhinds@redhat.com>
Tue, 14 Nov 2017 14:41:19 +0000 (14:41 +0000)
committerlhinds <lhinds@redhat.com>
Tue, 14 Nov 2017 14:49:00 +0000 (14:49 +0000)
Simple script to make it easier for projects to generate
checksums of binary files

Change-Id: Id246036b863e025c10791fdbc51168170413afc3
Signed-off-by: lhinds <lhinds@redhat.com>
utils/generate-sha256.py [new file with mode: 0644]

diff --git a/utils/generate-sha256.py b/utils/generate-sha256.py
new file mode 100644 (file)
index 0000000..c3efc58
--- /dev/null
@@ -0,0 +1,30 @@
+import os
+import sys
+import hashlib
+import argparse
+from binaryornot.check import is_binary
+
+hasher = hashlib.sha256()
+parser = argparse.ArgumentParser()
+
+parser.add_argument('--project', help="Full path to project folder", \
+       required=True)
+args = parser.parse_args()
+ignore_dirs = ['.git']
+sys.stdout = open('output.yaml' , 'w')
+
+print("binaries:")
+for root, dirs, files in os.walk(args.project):
+    dirs[:] = [d for d in dirs if d not in ignore_dirs]
+    for file in files:
+        path = os.path.join(root, file)
+        if is_binary(path):
+            with open(path, 'rb') as afile:
+                buf = afile.read()
+                hasher.update(buf)
+                print "  {}".format(file)
+                sum = hasher.hexdigest()
+                print "    - {}".format(sum)
+
+print("script run complete, now copy and paste contents of output.yaml into \
+       your project exception yaml file")