Created
October 13, 2014 23:24
-
-
Save pdxjohnny/1373aa617c48b3160a26 to your computer and use it in GitHub Desktop.
Simultaneous Android Device Flasher
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
#!/bin/python | |
from multiprocessing import Process | |
import sys | |
import subprocess | |
import time | |
def device_ids(): | |
device_ids = [] | |
devices = subprocess.check_output(["adb", "devices"]).split() | |
for device in xrange(0,len(devices)): | |
if devices[device] == "device": | |
device_ids.append(devices[device-1]) | |
return device_ids | |
def usb_ids(): | |
usb_ids = [] | |
usbs = subprocess.check_output(["fastboot", "devices", "-l"]).split() | |
for usb in xrange(0,len(usbs)): | |
if usbs[usb] == "fastboot": | |
usb_ids.append(usbs[usb+1]) | |
return usb_ids | |
def flash_device( usb_id ): | |
print "Starting flash for", usb_id | |
print usb_id, subprocess.check_output(["fastboot", "-s", usb_id, "oem", "unlock"]) | |
print usb_id, subprocess.check_output(["fastboot", "-s", usb_id, "flash", "gpt", gpt()]) | |
print usb_id, subprocess.check_output(["fastboot", "-s", usb_id, "flash", "bootloader", bootloader()]) | |
print usb_id, subprocess.check_output(["fastboot", "-s", usb_id, "flash", "fastboot", fastboot()]) | |
print usb_id, subprocess.check_output(["fastboot", "-s", usb_id, "update", img()]) | |
print "Finished flash for", usb_id | |
def gpt(): | |
for file_name in subprocess.check_output(["ls"]).split(): | |
if "gpt.ini" in file_name: | |
return file_name | |
def bootloader(): | |
for file_name in subprocess.check_output(["ls"]).split(): | |
if "bootloader" in file_name: | |
return file_name | |
def fastboot(): | |
for file_name in subprocess.check_output(["ls"]).split(): | |
if "fastboot.img" in file_name: | |
return file_name | |
def img(): | |
for file_name in subprocess.check_output(["ls"]).split(): | |
if "img.zip" in file_name: | |
return file_name | |
if __name__=='__main__': | |
devices = len(usb_ids()) | |
for device_id in device_ids(): | |
subprocess.check_output(["adb", "-s", device_id, "reboot-bootloader"]) | |
devices += 1 | |
fastboot_devices = len(usb_ids()) | |
print fastboot_devices, "of", devices, "devices ready..." | |
while fastboot_devices < devices: | |
time.sleep(2) | |
fastboot_devices = len(usb_ids()) | |
print "All", fastboot_devices, "devices ready..." | |
for usb_id in usb_ids(): | |
Process(target = flash_device, args=[usb_id,]).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment