github.com/vipernet-xyz/tendermint-core@v0.32.0/scripts/release_management/sha-files.py (about)

     1  #!/usr/bin/env python
     2  
     3  # Create SHA256 summaries from all ZIP files in a folder
     4  # Optimized for CircleCI
     5  
     6  import re
     7  import os
     8  import argparse
     9  import zipfile
    10  import hashlib
    11  
    12  
    13  BLOCKSIZE = 65536
    14  
    15  
    16  if __name__ == "__main__":
    17    parser = argparse.ArgumentParser()
    18    parser.add_argument("--folder", default="/tmp/workspace", help="Folder to look for, for ZIP files")
    19    parser.add_argument("--shafile", default="/tmp/workspace/SHA256SUMS", help="SHA256 summaries File")
    20    args = parser.parse_args()
    21  
    22    for filename in os.listdir(args.folder):
    23      if re.search('\.zip$',filename) is None:
    24        continue
    25      if not os.path.isfile(os.path.join(args.folder, filename)):
    26        continue
    27      with open(args.shafile,'a+') as shafile:
    28        hasher = hashlib.sha256()
    29        with open(os.path.join(args.folder, filename),'r') as f:
    30          buf = f.read(BLOCKSIZE)
    31          while len(buf) > 0:
    32            hasher.update(buf)
    33            buf = f.read(BLOCKSIZE)
    34        shafile.write("{0} {1}\n".format(hasher.hexdigest(),filename))  
    35