Use vendored boto to upload binaries
This commit is contained in:
Родитель
159a8165fe
Коммит
b28f234d28
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
|
@ -25,6 +26,10 @@ def main():
|
|||
if os.path.isdir(os.path.join(SRC_DIR, '.git')):
|
||||
rm_rf(SRC_DIR)
|
||||
|
||||
# Setup boto.
|
||||
with scoped_cwd(os.path.join('vendor', 'boto')):
|
||||
subprocess.call([sys.executable, 'setup.py', 'build'])
|
||||
|
||||
|
||||
def rm_rf(path):
|
||||
try:
|
||||
|
@ -34,5 +39,15 @@ def rm_rf(path):
|
|||
raise
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def scoped_cwd(path):
|
||||
cwd = os.getcwd()
|
||||
os.chdir(path)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
|
@ -10,10 +10,7 @@ import sys
|
|||
|
||||
|
||||
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
S3PUT = {
|
||||
'win32': [sys.executable, os.path.join(os.path.dirname(sys.executable),
|
||||
'Scripts', 's3put')],
|
||||
}.get(sys.platform, ['s3put'])
|
||||
BOTO_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'boto')
|
||||
|
||||
PLATFORM_KEY = {
|
||||
'cygwin': 'win',
|
||||
|
@ -27,9 +24,7 @@ def main():
|
|||
args = parse_args()
|
||||
|
||||
try:
|
||||
ensure_s3put()
|
||||
upload(args.target_arch)
|
||||
clean_up()
|
||||
except AssertionError as e:
|
||||
return e.message
|
||||
|
||||
|
@ -40,29 +35,6 @@ def parse_args():
|
|||
return parser.parse_args()
|
||||
|
||||
|
||||
def ensure_s3put():
|
||||
if sys.platform == 'linux2':
|
||||
return
|
||||
|
||||
output = ''
|
||||
try:
|
||||
output = command_output(S3PUT + ['--help'])
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
assert 'multipart' in output, 'Error: Please install boto and filechunkio'
|
||||
|
||||
if sys.platform != 'win32':
|
||||
return
|
||||
# multiprocessing on Windows requires that __main__ be discoverable via
|
||||
# imp.find_module(), which means it needs to end in a .py extension.
|
||||
import tempfile
|
||||
with tempfile.NamedTemporaryFile(suffix='.py', delete=False) as temp:
|
||||
with open(S3PUT[1]) as f:
|
||||
temp.write(f.read())
|
||||
S3PUT[1] = temp.name
|
||||
|
||||
|
||||
def upload(target_arch):
|
||||
os.chdir(SOURCE_ROOT)
|
||||
bucket, access_key, secret_key = s3_config()
|
||||
|
@ -73,18 +45,9 @@ def upload(target_arch):
|
|||
else:
|
||||
platform = PLATFORM_KEY
|
||||
|
||||
args = S3PUT + [
|
||||
'--bucket', bucket,
|
||||
'--access_key', access_key,
|
||||
'--secret_key', secret_key,
|
||||
'--prefix', SOURCE_ROOT,
|
||||
'--key_prefix', 'libchromiumcontent/{0}/{1}/{2}'.format(platform,
|
||||
target_arch,
|
||||
commit),
|
||||
'--grant', 'public-read',
|
||||
] + glob.glob('libchromiumcontent*.zip')
|
||||
|
||||
subprocess.check_call(args)
|
||||
s3put(bucket, access_key, secret_key, SOURCE_ROOT,
|
||||
'libchromiumcontent/{0}/{1}/{2}'.format(platform, target_arch, commit),
|
||||
glob.glob('libchromiumcontent*.zip'))
|
||||
|
||||
|
||||
def s3_config():
|
||||
|
@ -98,6 +61,35 @@ def s3_config():
|
|||
return config
|
||||
|
||||
|
||||
def boto_path_dirs():
|
||||
return [
|
||||
os.path.join(BOTO_DIR, 'build', 'lib'),
|
||||
os.path.join(BOTO_DIR, 'build', 'lib.linux-x86_64-2.7')
|
||||
]
|
||||
|
||||
|
||||
def run_boto_script(access_key, secret_key, script_name, *args):
|
||||
env = os.environ.copy()
|
||||
env['AWS_ACCESS_KEY_ID'] = access_key
|
||||
env['AWS_SECRET_ACCESS_KEY'] = secret_key
|
||||
env['PYTHONPATH'] = os.path.pathsep.join(
|
||||
[env.get('PYTHONPATH', '')] + boto_path_dirs())
|
||||
|
||||
boto = os.path.join(BOTO_DIR, 'bin', script_name)
|
||||
subprocess.call([sys.executable, boto] + list(args), env=env)
|
||||
|
||||
|
||||
def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
|
||||
args = [
|
||||
'--bucket', bucket,
|
||||
'--prefix', prefix,
|
||||
'--key_prefix', key_prefix,
|
||||
'--grant', 'public-read'
|
||||
] + files
|
||||
|
||||
run_boto_script(access_key, secret_key, 's3put', *args)
|
||||
|
||||
|
||||
def command_output(args):
|
||||
process = subprocess.Popen(args, stdout=subprocess.PIPE)
|
||||
output = process.communicate()[0]
|
||||
|
@ -106,13 +98,5 @@ def command_output(args):
|
|||
return output
|
||||
|
||||
|
||||
def clean_up():
|
||||
if sys.platform != 'win32':
|
||||
return
|
||||
|
||||
# Clean up the temporary file we created in ensure_s3put().
|
||||
os.unlink(S3PUT[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
Загрузка…
Ссылка в новой задаче