import subprocess

from lib_python import steps, execution, logger

__RESULT_OK = 0


def pull_file_via_adb(params):
    source = params["source"]
    destination = params["destination"]

    if subprocess.check_call("adb pull {0} {1}".format(source, destination), shell=True) != __RESULT_OK:
        logger.error("Pulling file from {0} into {1} via ADB has failed!".format(source, destination))
        execution.error("Pulling file from {0} into {1} via ADB has failed!".format(source, destination))

    execution.passed()


steps.new_step("ADB - Pull file from device at location {source} into {destination}", pull_file_via_adb)
