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