|
7 | 7 | import shlex |
8 | 8 | import sys |
9 | 9 |
|
10 | | -from util.logger import get_logger |
11 | 10 | import util.android as android |
12 | | - |
| 11 | +from util.logger import get_logger |
13 | 12 |
|
14 | 13 | log = get_logger("run_android_emulator") |
15 | 14 |
|
16 | 15 |
|
17 | 16 | def parse_args(): |
18 | 17 | parser = argparse.ArgumentParser( |
19 | 18 | description="Manages the running of an Android emulator. " |
20 | | - "Supported modes are to start and stop (default), only start, or only " |
21 | | - "stop the emulator.") |
| 19 | + "Supported modes are to create an AVD, and start or stop the emulator. " |
| 20 | + "The default is to start the emulator and wait for a keypress to stop it (start and stop)." |
| 21 | + ) |
22 | 22 |
|
23 | | - parser.add_argument( |
24 | | - "--create-avd", action="store_true", |
25 | | - help="Whether to create the Android virtual device.") |
| 23 | + parser.add_argument("--create-avd", action="store_true", help="Whether to create the Android virtual device.") |
26 | 24 |
|
27 | | - parser.add_argument( |
28 | | - "--start", action="store_true", help="Start the emulator.") |
29 | | - parser.add_argument( |
30 | | - "--stop", action="store_true", help="Stop the emulator.") |
| 25 | + parser.add_argument("--start", action="store_true", help="Start the emulator.") |
| 26 | + parser.add_argument("--stop", action="store_true", help="Stop the emulator.") |
31 | 27 |
|
| 28 | + parser.add_argument("--android-sdk-root", required=True, help="Path to the Android SDK root.") |
32 | 29 | parser.add_argument( |
33 | | - "--android-sdk-root", required=True, help="Path to the Android SDK root.") |
34 | | - parser.add_argument( |
35 | | - "--system-image", default="system-images;android-29;google_apis;x86_64", |
36 | | - help="The Android system image package name.") |
37 | | - parser.add_argument( |
38 | | - "--avd-name", default="ort_android", |
39 | | - help="The Android virtual device name.") |
| 30 | + "--system-image", |
| 31 | + default="system-images;android-31;default;x86_64", |
| 32 | + help="The Android system image package name.", |
| 33 | + ) |
| 34 | + parser.add_argument("--avd-name", default="ort_android", help="The Android virtual device name.") |
40 | 35 | parser.add_argument( |
41 | | - "--emulator-extra-args", default="", |
42 | | - help="A string of extra arguments to pass to the Android emulator.") |
| 36 | + "--emulator-extra-args", default="", help="A string of extra arguments to pass to the Android emulator." |
| 37 | + ) |
43 | 38 | parser.add_argument( |
44 | 39 | "--emulator-pid-file", |
45 | 40 | help="Output/input file containing the PID of the emulator process. " |
46 | | - "This is only required if exactly one of --start or --stop is given.") |
| 41 | + "This is only required if exactly one of --start or --stop is given.", |
| 42 | + ) |
47 | 43 |
|
48 | 44 | args = parser.parse_args() |
49 | 45 |
|
50 | | - if not args.start and not args.stop: |
51 | | - # unspecified means start and stop |
| 46 | + if not args.start and not args.stop and not args.create_avd: |
| 47 | + # unspecified means start and stop if not creating the AVD |
52 | 48 | args.start = args.stop = True |
53 | 49 |
|
54 | 50 | if args.start != args.stop and args.emulator_pid_file is None: |
@@ -84,10 +80,10 @@ def main(): |
84 | 80 | emulator_proc = android.start_emulator(**start_emulator_args) |
85 | 81 |
|
86 | 82 | with open(args.emulator_pid_file, mode="w") as emulator_pid_file: |
87 | | - print("{}".format(emulator_proc.pid), file=emulator_pid_file) |
| 83 | + print(f"{emulator_proc.pid}", file=emulator_pid_file) |
88 | 84 |
|
89 | 85 | elif args.stop: |
90 | | - with open(args.emulator_pid_file, mode="r") as emulator_pid_file: |
| 86 | + with open(args.emulator_pid_file) as emulator_pid_file: |
91 | 87 | emulator_pid = int(emulator_pid_file.readline().strip()) |
92 | 88 |
|
93 | 89 | android.stop_emulator(emulator_pid) |
|
0 commit comments