Last active
September 20, 2018 22:43
-
-
Save ndvo2710/357c31e00ae0c3a147bbffcc91e78814 to your computer and use it in GitHub Desktop.
Install Multiple APKs on multiple Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
import time | |
import shutil, zipfile | |
import subprocess, shlex | |
import argparse | |
import StringIO | |
HOME = os.getcwd() | |
def getAllDeviceIds(): | |
devices = [] | |
cmd = 'adb devices' | |
output = subprocess.check_output(shlex.split(cmd)) | |
lines = StringIO.StringIO(output) | |
lines.next() | |
while True: | |
try: | |
devices.append(lines.next().split('\t')[0]) | |
except Exception as e: | |
break | |
devices = filter(lambda x: x != '\n', devices) | |
return devices | |
def RunCommand(cmd): | |
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) | |
# Grab stdout line by line as it becomes available. This will loop until | |
# p terminates. | |
while p.poll() is None: | |
l = p.stdout.readline() # This blocks until it receives a newline. | |
print l | |
# When the subprocess terminates there might be unconsumed output | |
# that still needs to be processed. | |
print p.stdout.read() | |
time.sleep(5) | |
list_of_devices = getAllDeviceIds() | |
for device in list_of_devices: | |
cmd = 'adb install -s {} *.apk'.format(device) | |
RunCommand(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment