c3efc584aafd87084dd98850fb28fad04b60683e
[releng-anteater.git] / utils / generate-sha256.py
1 import os
2 import sys
3 import hashlib
4 import argparse
5 from binaryornot.check import is_binary
6
7 hasher = hashlib.sha256()
8 parser = argparse.ArgumentParser()
9
10 parser.add_argument('--project', help="Full path to project folder", \
11         required=True)
12 args = parser.parse_args()
13 ignore_dirs = ['.git']
14 sys.stdout = open('output.yaml' , 'w')
15
16 print("binaries:")
17 for root, dirs, files in os.walk(args.project):
18     dirs[:] = [d for d in dirs if d not in ignore_dirs]
19     for file in files:
20         path = os.path.join(root, file)
21         if is_binary(path):
22             with open(path, 'rb') as afile:
23                 buf = afile.read()
24                 hasher.update(buf)
25                 print "  {}".format(file)
26                 sum = hasher.hexdigest()
27                 print "    - {}".format(sum)
28
29 print("script run complete, now copy and paste contents of output.yaml into \
30         your project exception yaml file")