Flutter Engine
The Flutter Engine
create.py
Go to the documentation of this file.
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."""
10
11
12import argparse
13import glob
14import os
15import shutil
16import subprocess
17
18
19# See https://cloud.google.com/sdk/downloads#versioned for documentation on
20# scripting gcloud and also for updates.
21BASE_URL = 'https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/%s'
22GCLOUD_BASE_NAME='google-cloud-sdk'
23GCLOUD_ARCHIVE = '%s-343.0.0-linux-x86_64.tar.gz' % GCLOUD_BASE_NAME
24GCLOUD_URL = BASE_URL % GCLOUD_ARCHIVE
25
26
27def create_asset(target_dir):
28 """Create the asset."""
29 target_dir = os.path.abspath(target_dir)
30 subprocess.check_call(['curl', GCLOUD_URL, '-o', GCLOUD_ARCHIVE])
31
32 # Extract the arcive to the target directory and remove it.
33 subprocess.check_call(['tar', '-xzf', GCLOUD_ARCHIVE,
34 '--strip-components=1',
35 '-C', target_dir])
36
37 # Substitute the HOME directory in the environment so we don't overwrite
38 # an existing gcloud configuration in $HOME/.config/gcloud
39 env = os.environ.copy()
40 env["HOME"] = target_dir
41 gcloud_exe = os.path.join(target_dir, 'bin', 'gcloud')
42 subprocess.check_call([gcloud_exe, 'components',
43 'install', 'beta', 'cloud-datastore-emulator',
44 '--quiet'], env=env)
45 subprocess.check_call([gcloud_exe, 'components',
46 'install', 'beta', 'bigtable',
47 '--quiet'], env=env)
48 subprocess.check_call([gcloud_exe, 'components',
49 'install', 'pubsub-emulator',
50 '--quiet'], env=env)
51 subprocess.check_call([gcloud_exe, 'components',
52 'install', 'beta', 'cloud-firestore-emulator',
53 '--quiet'], env=env)
54 # As of gcloud v250.0.0 and Cloud Firestore Emulator v1.4.6, there is a bug
55 # that something expects the JAR to be executable, but it isn't.
56 fs_jar = 'platform/cloud-firestore-emulator/cloud-firestore-emulator.jar'
57 subprocess.check_call(['chmod', '+x', os.path.join(target_dir, fs_jar)])
58 subprocess.check_call([gcloud_exe, 'components','update', '--quiet'], env=env)
59
60 # Remove the tarball.
61 os.remove(GCLOUD_ARCHIVE)
62
63
64def main():
65 parser = argparse.ArgumentParser()
66 parser.add_argument('--target_dir', '-t', required=True)
67 args = parser.parse_args()
68 create_asset(args.target_dir)
69
70
71if __name__ == '__main__':
72 main()
def main()
Definition: create.py:69
def create_asset(target_dir)
Definition: create.py:32
Definition: main.py:1