python实现VTS和CTS-ON-GSI自动flash system.img脚本

  • Post author:
  • Post category:python


import os 
import time
import sys
import re
from colorama import init
 
init(autoreset=True)
a = sys.argv[1]
try:
	boot = sys.argv[2]
except:
	boot = " "
system = "system.img"

def flashGsi(a, boot, sn, s):
	os.system("adb -s {} reboot bootloader".format(sn))
	time.sleep(1)
	if a == "vts":
		os.system("fastboot flash boot {}".format(boot))
		time.sleep(1)
		os.system("fastboot -w")
	else:
		os.system("fastboot -w")
	time.sleep(1)
	os.system("fastboot reboot fastboot")
	time.sleep(2)
	os.system("fastboot flash system {}".format(system))
	time.sleep(5)
	os.system("fastboot reboot")
	print("\n")
	#output = '*'*int((s/2-37)) + "\033[0;32;40m\t{}:此设备刷GSI成功,正在重启中\033[0m".format(sn) + '*'*int((s/2-37))
	print("#####\033[0;32;40m{}:此设备刷GSI成功,正在重启中\033[0m#####".format(sn).center(s, '*'))

def getDevicesSn():
    SN_list = []
    device_info = os.popen('adb devices').read()
    for line in device_info.splitlines():
        if line == 'List of devices attached':
            continue
        else:
            com = re.compile('(.*?)\tde.*?')
            SN = re.findall(com, line)
            for i in SN:
                SN_list.append(i)
    return SN_list

if __name__ == '__main__':
    width = os.get_terminal_size().columns
    sn = getDevicesSn()
    for i in sn:
        print("\n"+ "#####\033[0;32;40m{}:此设备正在刷GSI,请稍等!\033[0m#####".format(i).center(width, '*'))
        flashGsi(a, boot, i, width)
        time.sleep(10)
    print("\n"+ "#####\033[0;32;40m共{}台手机刷GSI完成!\033[0m#####".format(len(sn)).center(width, '*'))
    time.sleep(2)
    if a == 'gsi':
        print("\n"+ "#####\033[0;31;40m请手动点击Allow USB debugging弹框\033[0m#####".center(width))
        time.sleep(75)
        os.system("python3 setting.py")
        time.sleep(1)
        os.system("python3 auto_media_push.py")
    else:
        time.sleep(75)
        os.system("python3 setting.py")
想了解,flash system.img开机后,VTS和CTS-on-GSI手机前期设置的小伙伴们,请关注我。



版权声明:本文为weixin_44546340原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。