• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2016 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 os
15import subprocess
16import sys
17import utils
18
19
20def main():
21  if 'linux' not in sys.platform:
22    print >> sys.stderr, 'This script only runs on Linux.'
23    sys.exit(1)
24  parser = argparse.ArgumentParser()
25  parser.add_argument('--gsutil')
26  parser.add_argument('--lib_path', '-l', required=True)
27  args = parser.parse_args()
28
29  with utils.tmp_dir():
30    cwd = os.getcwd()
31    create_script = os.path.join(common.FILE_DIR, 'create.py')
32    upload_script = os.path.join(common.FILE_DIR, 'upload.py')
33
34    try:
35      subprocess.check_call(['python', create_script,
36                             '-t', cwd,
37                             '-l', args.lib_path])
38      cmd = ['python', upload_script, '-t', cwd]
39      if args.gsutil:
40        cmd.extend(['--gsutil', args.gsutil])
41      subprocess.check_call(cmd)
42    except subprocess.CalledProcessError:
43      # Trap exceptions to avoid printing two stacktraces.
44      sys.exit(1)
45
46
47if __name__ == '__main__':
48  main()
49