You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1009 B

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