upload-node-checksums.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. import argparse
  3. import hashlib
  4. import os
  5. import tempfile
  6. from lib.config import s3_config
  7. from lib.util import download, rm_rf, s3put
  8. DIST_URL = 'https://atom.io/download/atom-shell/'
  9. def main():
  10. args = parse_args()
  11. url = DIST_URL + args.version + '/'
  12. directory, files = download_files(url, get_files_list(args.version))
  13. checksums = [
  14. create_checksum('sha1', directory, 'SHASUMS.txt', files),
  15. create_checksum('sha256', directory, 'SHASUMS256.txt', files)
  16. ]
  17. bucket, access_key, secret_key = s3_config()
  18. s3put(bucket, access_key, secret_key, directory,
  19. 'atom-shell/dist/{0}'.format(args.version), checksums)
  20. rm_rf(directory)
  21. def parse_args():
  22. parser = argparse.ArgumentParser(description='upload sumsha file')
  23. parser.add_argument('-v', '--version', help='Specify the version',
  24. required=True)
  25. return parser.parse_args()
  26. def get_files_list(version):
  27. return [
  28. 'node-{0}.tar.gz'.format(version),
  29. 'iojs-{0}.tar.gz'.format(version),
  30. 'iojs-{0}-headers.tar.gz'.format(version),
  31. 'node.lib',
  32. 'x64/node.lib',
  33. 'win-x86/iojs.lib',
  34. 'win-x64/iojs.lib',
  35. ]
  36. def download_files(url, files):
  37. directory = tempfile.mkdtemp(prefix='electron-tmp')
  38. return directory, [
  39. download(f, url + f, os.path.join(directory, f))
  40. for f in files
  41. ]
  42. def create_checksum(algorithm, directory, filename, files):
  43. lines = []
  44. for path in files:
  45. h = hashlib.new(algorithm)
  46. with open(path, 'r') as f:
  47. h.update(f.read())
  48. lines.append(h.hexdigest() + ' ' + os.path.relpath(path, directory))
  49. checksum_file = os.path.join(directory, filename)
  50. with open(checksum_file, 'w') as f:
  51. f.write('\n'.join(lines) + '\n')
  52. return checksum_file
  53. if __name__ == '__main__':
  54. import sys
  55. sys.exit(main())