From 3290c05e75a3669d05f7523ec29f783c6eb8cf35 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 12 May 2013 16:16:02 +0800 Subject: [PATCH] Add script to make distribution and upload. The scripts are stolen from aroben/libchromiumcontent. --- .gitignore | 2 ++ script/create-dist | 52 +++++++++++++++++++++++++++++++++++++++ script/upload | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100755 script/create-dist create mode 100755 script/upload diff --git a/.gitignore b/.gitignore index dd342440b8..9b26df2c96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .DS_Store +atom-shell.zip build/ +dist/ node/ node_modules/ vendor/ diff --git a/script/create-dist b/script/create-dist new file mode 100755 index 0000000000..74d5635e1f --- /dev/null +++ b/script/create-dist @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import errno +import os +import shutil + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') +BUNDLE_NAME = 'Atom.app' +BUNDLE_DIR = os.path.join(SOURCE_ROOT, 'build', 'Release', BUNDLE_NAME) + + +def main(): + rm_rf(DIST_DIR) + os.makedirs(DIST_DIR) + + copy_binaries() + create_zip() + + +def copy_binaries(): + shutil.copytree(BUNDLE_DIR, os.path.join(DIST_DIR, BUNDLE_NAME)) + + +def create_zip(): + print "Zipping distribution..." + zip_file = os.path.join(SOURCE_ROOT, 'atom-shell.zip') + safe_unlink(zip_file) + shutil.make_archive(os.path.splitext(zip_file)[0], 'zip', + root_dir=DIST_DIR) + + +def rm_rf(path): + try: + shutil.rmtree(path) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + +def safe_unlink(path): + try: + os.unlink(path) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + +if __name__ == '__main__': + import sys + sys.exit(main()) diff --git a/script/upload b/script/upload new file mode 100755 index 0000000000..e0387b54a7 --- /dev/null +++ b/script/upload @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import errno +import glob +import os +import subprocess + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + + +def main(): + try: + ensure_s3put() + upload() + except AssertionError as e: + return e.message + + +def ensure_s3put(): + output = '' + try: + output = subprocess.check_output(['s3put', '--help']) + except OSError as e: + if e.errno != errno.ENOENT: + raise + assert 'multipart' in output, 'Error: Please install boto and filechunkio' + + +def upload(): + os.chdir(SOURCE_ROOT) + bucket, access_key, secret_key = s3_config() + commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() + + args = [ + 's3put', + '--bucket', bucket, + '--access_key', access_key, + '--secret_key', secret_key, + '--prefix', SOURCE_ROOT, + '--key_prefix', 'atom-shell/{0}'.format(commit), + '--grant', 'public-read' + ] + glob.glob('atom-shell*.zip') + + subprocess.check_call(args) + + +def s3_config(): + config = (os.environ.get('ATOM_SHELL_S3_BUCKET', ''), + os.environ.get('ATOM_SHELL_S3_ACCESS_KEY', ''), + os.environ.get('ATOM_SHELL_S3_SECRET_KEY', '')) + message = ('Error: Please set the $ATOM_SHELL_S3_BUCKET, ' + '$ATOM_SHELL_S3_ACCESS_KEY, and ' + '$ATOM_SHELL_S3_SECRET_KEY environment variables') + assert all(len(c) for c in config), message + return config + + +if __name__ == '__main__': + import sys + sys.exit(main())