blob: 87c1872cf513da91e5729768b02685df48b77660 [file] [edit]
#!/usr/bin/env python3
# Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Script for uploading to x20 as a dependency in the same way we use cloud storage.
import argparse
import os
import shutil
import subprocess
import sys
import utils
GMS_CORE_DEPS = '/google/data/rw/teams/r8/deps'
def parse_options(argv=None):
parser = argparse.ArgumentParser(
description='Upload a dependency to x20 and internal GCS.')
parser.add_argument('name', help='Directory or file name to archive.')
return parser.parse_args(argv)
def upload_file(filename, dest):
print('Uploading to %s' % dest)
shutil.copyfile(filename, dest)
subprocess.check_call(['chmod', '664', dest])
def main():
options = parse_options()
name = options.name
print('Creating archive for %s' % name)
if name not in os.listdir('.'):
print(
'You must be standing directly below the directory you are uploading'
)
return 1
filename = utils.create_archive(name)
sha1 = utils.get_sha1(filename)
dest = os.path.join(GMS_CORE_DEPS, sha1)
upload_file(filename, dest)
gcs_dest = '%s/%s' % (utils.R8_INTERNAL_DEPS_BUCKET, sha1)
print('Uploading to %s' % gcs_dest)
utils.upload_file_to_cloud_storage(filename, gcs_dest)
sha1_file = '%s.sha1' % filename
with open(sha1_file, 'w') as output:
output.write(sha1)
print('Sha (%s) written to: %s' % (sha1, sha1_file))
return 0
if __name__ == '__main__':
sys.exit(main())