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  args = parser.parse_args()
27
28  with utils.tmp_dir():
29    cwd = os.getcwd()
30    create_script = os.path.join(common.FILE_DIR, 'create.py')
31    upload_script = os.path.join(common.FILE_DIR, 'upload.py')
32
33    try:
34      cwd = os.path.join(cwd, 'sysroot')
35      subprocess.check_call(['python', create_script, '-t', cwd])
36      cmd = ['python', upload_script, '-t', cwd]
37      if args.gsutil:
38        cmd.extend(['--gsutil', args.gsutil])
39      subprocess.check_call(cmd)
40    except subprocess.CalledProcessError:
41      # Trap exceptions to avoid printing two stacktraces.
42      sys.exit(1)
43
44
45if __name__ == '__main__':
46  main()
47