qemu-stamp.py 614 B

123456789101112131415161718192021222324
  1. #! /usr/bin/env python3
  2. # Usage: scripts/qemu-stamp.py STRING1 STRING2... -- FILE1 FILE2...
  3. import hashlib
  4. import os
  5. import sys
  6. sha = hashlib.sha1()
  7. is_file = False
  8. for arg in sys.argv[1:]:
  9. if arg == '--':
  10. is_file = True
  11. continue
  12. if is_file:
  13. with open(arg, 'rb') as f:
  14. for chunk in iter(lambda: f.read(65536), b''):
  15. sha.update(chunk)
  16. else:
  17. sha.update(os.fsencode(arg))
  18. sha.update(b'\n')
  19. # The hash can start with a digit, which the compiler doesn't
  20. # like as an symbol. So prefix it with an underscore
  21. print("_" + sha.hexdigest())