Esempio n. 1
0
def push(src, cleanup=False):
    dst = get_push_pack_directory()
    if dst is None:
        return -1
    result = stop_horizon()

    if result != 0:
        from fancy_output import print_err
        print_err("no devices/emulators found")
        print_err("connect to ADB first")
        return result


#   if cleanup:
#       result = subprocess.call([make_config.get_adb(), "shell", "rm", "-r", dst])
#       if result != 0:
#           print(f"failed to cleanup directory {dst} with code {result}")
#           return result
    dst = dst.replace("\\", "/")
    if dst[0] != "/":
        dst = "/" + dst

    src_push = src.replace("\\", "/")
    #   if src_push[-1] != "/":
    #       src_push += "/"
    #   src_push += "."

    subprocess.call([make_config.get_adb(), "shell", "rm", "-r", dst],
                    stderr=ignore,
                    stdout=ignore)

    files = [
        file[len(src_push) + 1:].replace("\\", "/")
        for file in glob.glob(f"{src_push}/**/*", recursive=True)
    ]
    file_count = len(files)
    result = 0

    progress = 0
    for file in files:
        source = os.path.join(src_push, file)
        destination = os.path.join(dst, file).replace("\\", "/")

        result += subprocess.call(
            [make_config.get_adb(), "push", source, destination],
            stdout=ignore,
            stderr=subprocess.STDOUT)

        progress += 1
        percent = int(100 * (progress / file_count))

        bar = f"|{'█' * percent}{' ' * (100 - percent)}| {percent}%"
        print(bar, end="\r")

        if file == files[-1]:
            print()

    if result != 0:
        print(f"failed to push to directory {dst} with code {result}")
    return result
Esempio n. 2
0
def push(directory, cleanup=False):
    items = glob(directory + "/*")
    changed = [
        os.path.relpath(path, directory) for path in items
        if storage.is_path_changed(path)
    ]

    if len(changed) < 1:
        print_progress_bar(1, 1, suffix='Complete!', length=50)
        return 0

    dst_root = get_push_pack_directory()
    if dst_root is None:
        return -1

    result = subprocess.call([make_config.get_adb(), "devices"],
                             stderr=ignore,
                             stdout=ignore)
    if result != 0:
        print(
            "\033[91mno devices/emulators found, try to use task \"Connect to ADB\"\033[0m"
        )
        return result

    dst_root = dst_root.replace("\\", "/")
    if not dst_root.startswith("/"):
        dst_root = "/" + dst_root

    src_root = directory.replace("\\", "/")

    progress = 0
    for filename in changed:
        src = src_root + "/" + filename
        dst = dst_root + "/" + filename
        print_progress_bar(progress,
                           len(changed),
                           suffix=f'Pushing {filename}' + (" " * 20),
                           length=50)
        subprocess.call([make_config.get_adb(), "shell", "rm", "-r", dst],
                        stderr=ignore,
                        stdout=ignore)
        result = subprocess.call([make_config.get_adb(), "push", src, dst],
                                 stderr=ignore,
                                 stdout=ignore)
        progress += 1

        if result != 0:
            print(f"failed to push to directory {dst_root} with code {result}")
            return result

    print_progress_bar(progress,
                       len(changed),
                       suffix=f'Complete!' + (" " * 20),
                       length=50)
    storage.save()
    return result
Esempio n. 3
0
def make_locks(*locks):
    dst = get_push_pack_directory()
    if dst is None:
        return -1
    stop_horizon()
    for lock in locks:
        lock = os.path.join(dst, lock).replace("\\", "/")
        result = subprocess.call(
            [make_config.get_adb(), "shell", "touch", lock])
        if result != 0:
            return result
    return 0
Esempio n. 4
0
def stop_horizon():
    return subprocess.call([
        make_config.get_adb(), "shell", "am", "force-stop", "com.zheka.horizon"
    ])