IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

47 wiersze
1.2KB

  1. import hashlib
  2. import json
  3. def filehash(fname):
  4. h = hashlib.sha256()
  5. with open(fname, 'rb') as f:
  6. while True:
  7. data = f.read(1024*1024*4)
  8. if not data:
  9. break
  10. h.update(data)
  11. res = h.hexdigest()
  12. return res
  13. class RunStep(object):
  14. def __init__(self, base, spec):
  15. self.base = base
  16. self.spec = spec
  17. def hash(self):
  18. res = hashlib.sha256(
  19. json.dumps(( self.base, self.spec ))
  20. .encode('utf-8')).hexdigest()
  21. return res
  22. class CopyStep(object):
  23. def __init__(self, base, spec):
  24. if not isinstance(spec, list):
  25. raise ValueError('CopyStep spec should be a list')
  26. self.base = base
  27. self.spec = spec
  28. def hash(self):
  29. if len(self.spec) == 0:
  30. fh = []
  31. elif isinstance(self.spec[0], list):
  32. fh = list(map(lambda a: filehash(a[0]), self.spec))
  33. else:
  34. fh = [ filehash(self.spec[0]) ]
  35. res = hashlib.sha256(
  36. json.dumps(( self.base, fh, self.spec ))
  37. .encode('utf-8')).hexdigest()
  38. return res