1 #!/usr/bin/env python 2 # 3 # Copyright 2017 Google Inc. 4 # 5 # Use of this source code is governed by a BSD-style license that can be 6 # found in the LICENSE file. 7 8 9 """Create the asset and upload it.""" 10 11 12 import argparse 13 import common 14 import shutil 15 import os 16 import subprocess 17 import sys 18 import utils 19 20 21 def main(): 22 parser = argparse.ArgumentParser() 23 parser.add_argument('--gsutil') 24 args = parser.parse_args() 25 26 with utils.tmp_dir(): 27 cwd = os.getcwd() 28 workdir = os.path.join(cwd, "workdir") 29 create_script = os.path.join(common.FILE_DIR, 'create.py') 30 upload_script = os.path.join(common.FILE_DIR, 'upload.py') 31 32 try: 33 os.mkdir(workdir) 34 subprocess.check_call(['python', create_script, '-t', workdir]) 35 cmd = ['python', upload_script, '-t', workdir] 36 if args.gsutil: 37 cmd.extend(['--gsutil', args.gsutil]) 38 subprocess.check_call(cmd) 39 except subprocess.CalledProcessError: 40 # Trap exceptions to avoid printing two stacktraces. 41 sys.exit(1) 42 43 if __name__ == '__main__': 44 main() 45