• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
12import argparse
13import common
14import shutil
15import os
16import subprocess
17import sys
18import utils
19
20
21def 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
43if __name__ == '__main__':
44  main()
45