import os, sys
def devices():
    os.system('fastboot devices')

def unlock():
    unlock = os.popen('fastboot getvar unlocked 2>&1').read()
    if "yes" not in unlock:
        check_unlock = os.popen('fastboot flashing get_unlock_ability 2>&1').read()
        if check_unlock == "(bootloader) get_unlock_ability: 1":
            input('Please note: Unlocking the bootloader will wipe any data on the device. If you need to pull data from a locked device please exit the program and use a different method!!')
            os.system('fastboot flashing unlock')
            input('Ensure that unlocking is complete on the device before pressing enter.')
        else:
            print("OEM Unlocking not supported on this device.")
            sys.exit()
    else:
        print("Device already unlocked.")

def boot(img):
    os.system('fastboot boot ' + img)