-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_apk.py
More file actions
50 lines (47 loc) · 2.15 KB
/
install_apk.py
File metadata and controls
50 lines (47 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from android_scripts_python.library import main_functions
from android_scripts_python.library.device_operations import display_selected_device, is_adb_device
from android_scripts_python.library.machine_file_operations import build_machine_files_list
from android_scripts_python.library.configure_machine import myAppDir
def install_machine_files(device_serial, main_folder, sub_folder, search_string):
# Check if subfolder exists, else prompt to use main folder
folder_path = os.path.join(main_folder, sub_folder)
if not os.path.isdir(folder_path):
use_default = input(f"{sub_folder} folder does not exist in {main_folder} ...\n\n Do you want to install from {main_folder} instead [y/n]: ")
if use_default.lower() == 'y':
folder_path = main_folder
else:
print("Aborted.")
return
files = build_machine_files_list(folder_path, search_string)
if not files:
print(f"There are no matching files in the directory: {folder_path}\n")
return
for apk_path in files:
apk_name = os.path.basename(apk_path)
yn = input(f"Do you want to install [y/n] - {apk_name}: ")
if yn.lower() == 'y':
print(f"\nInstalling {apk_name} ...")
output = main_functions.adb_shell(device_serial, "wait-for-device", "install", "-r", "-d", apk_path)
print(output)
print("...Done\n")
def main():
main_functions.get_device_choice()
display_selected_device(main_functions.deviceSerial)
if is_adb_device(main_functions.deviceSerial):
if len(sys.argv) < 3:
if len(sys.argv) < 2:
sub_folder = input(" Enter the Folder name (Case-sensitive): ")
else:
sub_folder = sys.argv[1]
search_string = ".apk"
else:
sub_folder = sys.argv[1]
search_string = sys.argv[2]
install_machine_files(main_functions.deviceSerial, myAppDir, sub_folder, search_string)
else:
print(" Device not in 'adb' mode")
if __name__ == "__main__":
main()