2013-06-24 09:56:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import subprocess
|
2013-06-29 03:36:02 +00:00
|
|
|
import sys
|
2013-06-24 09:56:51 +00:00
|
|
|
import tempfile
|
|
|
|
|
2013-06-29 03:36:02 +00:00
|
|
|
from lib.util import *
|
|
|
|
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
ensure_s3put()
|
2013-06-29 03:36:02 +00:00
|
|
|
if not dist_newer_than_head():
|
|
|
|
create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
|
|
|
|
subprocess.check_call([sys.executable, create_dist])
|
2013-06-24 09:56:51 +00:00
|
|
|
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'
|
|
|
|
|
|
|
|
|
2013-06-29 03:36:02 +00:00
|
|
|
def dist_newer_than_head():
|
|
|
|
with scoped_cwd(SOURCE_ROOT):
|
|
|
|
try:
|
|
|
|
head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
|
|
|
|
'-n', '1']).strip()
|
|
|
|
dist_time = os.path.getmtime(os.path.join(SOURCE_ROOT, 'atom-shell.zip'))
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
return False
|
|
|
|
|
|
|
|
return dist_time > int(head_time)
|
|
|
|
|
|
|
|
|
2013-06-24 09:56:51 +00:00
|
|
|
def upload():
|
|
|
|
os.chdir(SOURCE_ROOT)
|
|
|
|
bucket, access_key, secret_key = s3_config()
|
|
|
|
|
2013-08-12 07:01:05 +00:00
|
|
|
version = get_atom_shell_version()
|
2013-07-03 09:46:14 +00:00
|
|
|
s3put(bucket, access_key, secret_key, SOURCE_ROOT,
|
2013-08-12 07:01:05 +00:00
|
|
|
'atom-shell/{0}'.format(version), glob.glob('atom-shell*.zip'))
|
2013-06-24 09:56:51 +00:00
|
|
|
|
2013-06-29 03:52:58 +00:00
|
|
|
update_version(bucket, access_key, secret_key)
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-06-29 03:52:58 +00:00
|
|
|
def update_version(bucket, access_key, secret_key):
|
2013-07-03 09:46:14 +00:00
|
|
|
prefix = os.path.join(SOURCE_ROOT, 'dist')
|
|
|
|
version = os.path.join(prefix, 'version')
|
|
|
|
s3put(bucket, access_key, secret_key, prefix, 'atom-shell', [ version ])
|
2013-06-24 09:56:51 +00:00
|
|
|
|
|
|
|
|
2013-07-03 09:46:14 +00:00
|
|
|
def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
|
2013-06-24 09:56:51 +00:00
|
|
|
args = [
|
|
|
|
's3put',
|
|
|
|
'--bucket', bucket,
|
|
|
|
'--access_key', access_key,
|
|
|
|
'--secret_key', secret_key,
|
2013-07-03 09:46:14 +00:00
|
|
|
'--prefix', prefix,
|
2013-06-24 09:56:51 +00:00
|
|
|
'--key_prefix', key_prefix,
|
|
|
|
'--grant', 'public-read'
|
|
|
|
] + files
|
|
|
|
|
|
|
|
subprocess.check_call(args)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
sys.exit(main())
|