| 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 |
| 23 | |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 24 | from acloud.internal.lib import utils |
| 25 | from acloud.setup import host_setup_runner |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 26 | from acloud.setup import gcp_setup_runner |
| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 27 | |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 28 | |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 29 | def Run(args): |
| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 30 | """Run setup. |
| 31 | |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 32 | Setup options: |
| 33 | -host: Setup host settings. |
| 34 | -gcp_init: Setup gcp settings. |
| 35 | -None, default behavior will setup host and gcp settings. |
| 36 | |
| Kevin Cheng | ee6030f | 2018-06-26 10:55:30 -0700 | [diff] [blame] | 37 | Args: |
| 38 | args: Namespace object from argparse.parse_args. |
| 39 | """ |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 40 | # Setup process will be in the following manner: |
| 41 | # 1.Print welcome message. |
| 42 | _PrintWelcomeMessage() |
| 43 | |
| 44 | # 2.Init all subtasks in queue and traverse them. |
| chojoyce | 1b818bb | 2018-10-03 16:34:57 +0800 | [diff] [blame] | 45 | host_runner = host_setup_runner.AvdPkgInstaller() |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 46 | host_env_runner = host_setup_runner.CuttlefishHostSetup() |
| 47 | gcp_runner = gcp_setup_runner.GcpTaskRunner(args.config_file) |
| 48 | task_queue = [] |
| 49 | if args.host or not args.gcp_init: |
| 50 | task_queue.append(host_runner) |
| 51 | task_queue.append(host_env_runner) |
| 52 | if args.gcp_init or not args.host: |
| 53 | task_queue.append(gcp_runner) |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 54 | |
| 55 | for subtask in task_queue: |
| Kevin Cheng | 58b7e79 | 2018-10-05 02:26:53 -0700 | [diff] [blame] | 56 | subtask.Run(force_setup=args.force) |
| Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 57 | |
| 58 | # 3.Print the usage hints. |
| 59 | _PrintUsage() |
| 60 | |
| 61 | |
| 62 | def _PrintWelcomeMessage(): |
| 63 | """Print welcome message when acloud setup been called.""" |
| 64 | |
| 65 | # pylint: disable=anomalous-backslash-in-string |
| 66 | asc_art = " \n" \ |
| 67 | " ___ _______ ____ __ _____ \n" \ |
| 68 | " / _ |/ ___/ / / __ \/ / / / _ \\ \n" \ |
| 69 | " / __ / /__/ /__/ /_/ / /_/ / // / \n" \ |
| 70 | "/_/ |_\\___/____/\\____/\\____/____/ \n" \ |
| 71 | " \n" |
| 72 | |
| 73 | print("\nWelcome to") |
| 74 | print(asc_art) |
| 75 | |
| 76 | |
| 77 | def _PrintUsage(): |
| 78 | """Print cmd usage hints when acloud setup been finished.""" |
| herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 79 | utils.PrintColorString("") |
| 80 | utils.PrintColorString("Setup process finished") |
| 81 | utils.PrintColorString("To get started creating AVDs, run '#acloud create'") |