blob: 8af7907dc8d385f39e4665f272bbbd4d840b65cc [file] [log] [blame]
Kevin Chengee6030f2018-06-26 10:55:30 -07001#!/usr/bin/env python
2#
3# Copyright 2018 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16r"""Setup entry point.
17
18Setup will handle all of the necessary steps to enable acloud to create a local
19or remote instance of an Android Virtual Device.
20"""
21
22from __future__ import print_function
Kevin Cheng99cf3d32018-10-05 02:09:21 -070023import os
24import subprocess
Kevin Chengee6030f2018-06-26 10:55:30 -070025
Sam Chiu81bdc652018-06-29 18:45:08 +080026from acloud.internal.lib import utils
27from acloud.setup import host_setup_runner
herbertxue34776bb2018-07-03 21:57:48 +080028from acloud.setup import gcp_setup_runner
Kevin Chengee6030f2018-06-26 10:55:30 -070029
Sam Chiu81bdc652018-06-29 18:45:08 +080030
herbertxue34776bb2018-07-03 21:57:48 +080031def Run(args):
Kevin Chengee6030f2018-06-26 10:55:30 -070032 """Run setup.
33
herbertxue34776bb2018-07-03 21:57:48 +080034 Setup options:
35 -host: Setup host settings.
36 -gcp_init: Setup gcp settings.
37 -None, default behavior will setup host and gcp settings.
38
Kevin Chengee6030f2018-06-26 10:55:30 -070039 Args:
40 args: Namespace object from argparse.parse_args.
41 """
Kevin Cheng99cf3d32018-10-05 02:09:21 -070042 _RunPreSetup()
43
Sam Chiu81bdc652018-06-29 18:45:08 +080044 # Setup process will be in the following manner:
45 # 1.Print welcome message.
46 _PrintWelcomeMessage()
47
48 # 2.Init all subtasks in queue and traverse them.
chojoyce1b818bb2018-10-03 16:34:57 +080049 host_runner = host_setup_runner.AvdPkgInstaller()
herbertxue34776bb2018-07-03 21:57:48 +080050 host_env_runner = host_setup_runner.CuttlefishHostSetup()
51 gcp_runner = gcp_setup_runner.GcpTaskRunner(args.config_file)
52 task_queue = []
53 if args.host or not args.gcp_init:
54 task_queue.append(host_runner)
55 task_queue.append(host_env_runner)
56 if args.gcp_init or not args.host:
57 task_queue.append(gcp_runner)
Sam Chiu81bdc652018-06-29 18:45:08 +080058
59 for subtask in task_queue:
Kevin Cheng58b7e792018-10-05 02:26:53 -070060 subtask.Run(force_setup=args.force)
Sam Chiu81bdc652018-06-29 18:45:08 +080061
62 # 3.Print the usage hints.
63 _PrintUsage()
64
65
66def _PrintWelcomeMessage():
67 """Print welcome message when acloud setup been called."""
68
69 # pylint: disable=anomalous-backslash-in-string
70 asc_art = " \n" \
71 " ___ _______ ____ __ _____ \n" \
72 " / _ |/ ___/ / / __ \/ / / / _ \\ \n" \
73 " / __ / /__/ /__/ /_/ / /_/ / // / \n" \
74 "/_/ |_\\___/____/\\____/\\____/____/ \n" \
75 " \n"
76
77 print("\nWelcome to")
78 print(asc_art)
79
80
81def _PrintUsage():
82 """Print cmd usage hints when acloud setup been finished."""
herbertxue34776bb2018-07-03 21:57:48 +080083 utils.PrintColorString("")
84 utils.PrintColorString("Setup process finished")
Kevin Cheng99cf3d32018-10-05 02:09:21 -070085
86
87def _RunPreSetup():
88 """This will run any pre-setup scripts.
89
90 If we can find any pre-setup scripts, run it and don't care about the
91 results. Pre-setup scripts will do any special setup before actual
92 setup occurs (e.g. copying configs).
93 """
94 build_top = os.environ.get("ANDROID_BUILD_TOP")
95 if build_top is None:
96 return
97 pre_setup_sh = os.path.join(build_top, "tools", "acloud", "setup",
98 "pre_setup_sh", "acloud_pre_setup.sh")
99 if os.path.exists(pre_setup_sh):
100 subprocess.call([pre_setup_sh])