| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 1 | #!/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. |
| 16 | r"""Setup entry point. |
| 17 | |
| 18 | Setup will handle all of the necessary steps to enable acloud to create a local |
| 19 | or remote instance of an Android Virtual Device. |
| 20 | """ |
| 21 | |
| 22 | from __future__ import print_function |
| Kevin Cheng | 99cf3d3 | 2018-10-05 02:09:21 -0700 | [diff] [blame] | 23 | import os |
| 24 | import subprocess |
| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 25 | |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 26 | from acloud.internal.lib import utils |
| 27 | from acloud.setup import host_setup_runner |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 28 | from acloud.setup import gcp_setup_runner |
| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 29 | |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 30 | |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 31 | def Run(args): |
| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 32 | """Run setup. |
| 33 | |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 34 | 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 Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 39 | Args: |
| 40 | args: Namespace object from argparse.parse_args. |
| 41 | """ |
| Kevin Cheng | 99cf3d3 | 2018-10-05 02:09:21 -0700 | [diff] [blame] | 42 | _RunPreSetup() |
| 43 | |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 44 | # 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. |
| chojoyce | 1b818bb | 2018-10-03 16:34:57 +0800 | [diff] [blame] | 49 | host_runner = host_setup_runner.AvdPkgInstaller() |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 50 | 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 Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 58 | |
| 59 | for subtask in task_queue: |
| Kevin Cheng | 58b7e79 | 2018-10-05 02:26:53 -0700 | [diff] [blame] | 60 | subtask.Run(force_setup=args.force) |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 61 | |
| 62 | # 3.Print the usage hints. |
| 63 | _PrintUsage() |
| 64 | |
| 65 | |
| 66 | def _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 | |
| 81 | def _PrintUsage(): |
| 82 | """Print cmd usage hints when acloud setup been finished.""" |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 83 | utils.PrintColorString("") |
| 84 | utils.PrintColorString("Setup process finished") |
| Kevin Cheng | 99cf3d3 | 2018-10-05 02:09:21 -0700 | [diff] [blame] | 85 | |
| 86 | |
| 87 | def _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]) |