aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorlhinds <lhinds@redhat.com>2017-11-16 17:03:43 +0000
committerlhinds <lhinds@redhat.com>2017-11-16 17:03:43 +0000
commit21eba438574c13ecd49119ab9a7df882e517f566 (patch)
treea924ff83757897f24525b66467fd49efadacb590 /utils
parent8365245c9dc2f8e2ff2adf8aa84162e420747132 (diff)
Implements full path for hash checks of binaries
Previously the hash check would work only against the filename, and not using the relative path. This change uses the whole relative path to allow indentical filenames in different folder locations within the same repo. Also updated the generate-sha256.py script to introduce the same changes. JIRA: RELENG-303 Change-Id: I3a59e015b708eb5a966690b9839e5e15ac5b64c7 Signed-off-by: lhinds <lhinds@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/generate-sha256.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/utils/generate-sha256.py b/utils/generate-sha256.py
index c3efc58..89ecf59 100644
--- a/utils/generate-sha256.py
+++ b/utils/generate-sha256.py
@@ -1,3 +1,15 @@
+##############################################################################
+# Copyright (c) 2017 Luke Hinds <lhinds@redhat.com>, Red Hat
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# python generate-sha256.py --project /home/user/opnfv/infra
+# output made to working directory, file `output.yaml`
+
import os
import sys
import hashlib
@@ -7,24 +19,22 @@ from binaryornot.check import is_binary
hasher = hashlib.sha256()
parser = argparse.ArgumentParser()
-parser.add_argument('--project', help="Full path to project folder", \
- required=True)
+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')
+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:
+ full_path = os.path.join(root, file)
+ if is_binary(full_path):
+ with open(full_path, 'rb') as afile:
buf = afile.read()
hasher.update(buf)
- print " {}".format(file)
+ split_path = full_path.split(args.project + '/', 1)[-1]
+ print(" {}:".format(split_path))
sum = hasher.hexdigest()
- print " - {}".format(sum)
-
-print("script run complete, now copy and paste contents of output.yaml into \
- your project exception yaml file")
+ print(" - {}".format(sum))