2014-07-21 08:31:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import hashlib
|
|
|
|
import os
|
2018-03-14 03:59:18 +00:00
|
|
|
import shutil
|
2018-09-16 17:24:07 +00:00
|
|
|
import sys
|
2014-07-21 08:31:51 +00:00
|
|
|
import tempfile
|
|
|
|
|
2019-06-26 18:32:42 +00:00
|
|
|
sys.path.append(
|
|
|
|
os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../.."))
|
2019-06-24 17:18:04 +00:00
|
|
|
|
2022-04-04 09:32:57 +00:00
|
|
|
from lib.util import download, rm_rf, store_artifact, safe_mkdir
|
2014-07-21 08:31:51 +00:00
|
|
|
|
2019-05-21 07:17:08 +00:00
|
|
|
DIST_URL = 'https://electronjs.org/headers/'
|
2014-07-21 08:31:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
2018-03-14 03:59:18 +00:00
|
|
|
dist_url = args.dist_url
|
|
|
|
if dist_url[-1] != "/":
|
|
|
|
dist_url += "/"
|
2014-07-21 08:31:51 +00:00
|
|
|
|
2018-03-14 03:59:18 +00:00
|
|
|
url = dist_url + args.version + '/'
|
2014-07-21 08:31:51 +00:00
|
|
|
directory, files = download_files(url, get_files_list(args.version))
|
|
|
|
checksums = [
|
|
|
|
create_checksum('sha1', directory, 'SHASUMS.txt', files),
|
|
|
|
create_checksum('sha256', directory, 'SHASUMS256.txt', files)
|
|
|
|
]
|
|
|
|
|
2018-03-14 03:59:18 +00:00
|
|
|
if args.target_dir is None:
|
2022-04-04 09:32:57 +00:00
|
|
|
store_artifact(directory, 'atom-shell/dist/{0}'.format(args.version),
|
|
|
|
checksums)
|
2018-03-14 03:59:18 +00:00
|
|
|
else:
|
|
|
|
copy_files(checksums, args.target_dir)
|
2014-07-21 08:31:51 +00:00
|
|
|
|
|
|
|
rm_rf(directory)
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='upload sumsha file')
|
|
|
|
parser.add_argument('-v', '--version', help='Specify the version',
|
|
|
|
required=True)
|
2018-03-14 03:59:18 +00:00
|
|
|
parser.add_argument('-u', '--dist-url',
|
|
|
|
help='Specify the dist url for downloading',
|
|
|
|
required=False, default=DIST_URL)
|
|
|
|
parser.add_argument('-t', '--target-dir',
|
|
|
|
help='Specify target dir of checksums',
|
|
|
|
required=False)
|
2014-07-21 08:31:51 +00:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
def get_files_list(version):
|
|
|
|
return [
|
2018-03-14 03:59:18 +00:00
|
|
|
{ "filename": 'node-{0}.tar.gz'.format(version), "required": True },
|
2018-09-27 12:38:41 +00:00
|
|
|
{ "filename": 'node-{0}-headers.tar.gz'.format(version), "required": True },
|
2018-03-14 03:59:18 +00:00
|
|
|
{ "filename": 'iojs-{0}.tar.gz'.format(version), "required": True },
|
|
|
|
{ "filename": 'iojs-{0}-headers.tar.gz'.format(version), "required": True },
|
|
|
|
{ "filename": 'node.lib', "required": False },
|
|
|
|
{ "filename": 'x64/node.lib', "required": False },
|
|
|
|
{ "filename": 'win-x86/iojs.lib', "required": False },
|
2018-09-27 12:38:41 +00:00
|
|
|
{ "filename": 'win-x64/iojs.lib', "required": False },
|
|
|
|
{ "filename": 'win-x86/node.lib', "required": False },
|
2019-09-17 16:38:36 +00:00
|
|
|
{ "filename": 'win-x64/node.lib', "required": False },
|
|
|
|
{ "filename": 'arm64/node.lib', "required": False },
|
|
|
|
{ "filename": 'win-arm64/iojs.lib', "required": False },
|
|
|
|
{ "filename": 'win-arm64/node.lib', "required": False }
|
2014-07-21 08:31:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def download_files(url, files):
|
2015-04-12 14:23:50 +00:00
|
|
|
directory = tempfile.mkdtemp(prefix='electron-tmp')
|
2018-03-14 03:59:18 +00:00
|
|
|
result = []
|
|
|
|
for optional_f in files:
|
2018-03-15 17:20:41 +00:00
|
|
|
required = optional_f['required']
|
|
|
|
f = optional_f['filename']
|
2018-03-14 03:59:18 +00:00
|
|
|
try:
|
|
|
|
result.append(download(f, url + f, os.path.join(directory, f)))
|
|
|
|
except Exception:
|
|
|
|
if required:
|
|
|
|
raise
|
|
|
|
|
|
|
|
return directory, result
|
2014-07-21 08:31:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_checksum(algorithm, directory, filename, files):
|
|
|
|
lines = []
|
|
|
|
for path in files:
|
|
|
|
h = hashlib.new(algorithm)
|
2021-04-19 19:55:17 +00:00
|
|
|
with open(path, 'rb') as f:
|
2014-07-21 08:31:51 +00:00
|
|
|
h.update(f.read())
|
|
|
|
lines.append(h.hexdigest() + ' ' + os.path.relpath(path, directory))
|
|
|
|
|
|
|
|
checksum_file = os.path.join(directory, filename)
|
|
|
|
with open(checksum_file, 'w') as f:
|
|
|
|
f.write('\n'.join(lines) + '\n')
|
|
|
|
return checksum_file
|
|
|
|
|
2018-03-14 03:59:18 +00:00
|
|
|
def copy_files(source_files, output_dir):
|
|
|
|
for source_file in source_files:
|
|
|
|
output_path = os.path.join(output_dir, os.path.basename(source_file))
|
|
|
|
safe_mkdir(os.path.dirname(output_path))
|
|
|
|
shutil.copy2(source_file, output_path)
|
2014-07-21 08:31:51 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|