#!/usr/bin/env python3

import shutil
import sys
from pathlib import Path


def usage():
    print("series2epatch Python script version 0.5.0")
    print("Usage: go-series2epatch <start number> <source dir> <destination dir>")


def main(argv):
    if len(argv) == 2 and argv[1] in ("--help", "-h"):
        usage()
        return 0
    if len(argv) == 2 and argv[1] in ("--version", "-V"):
        print("go-utils 0.5.0")
        return 0
    if len(argv) != 4:
        usage()
        return 1

    counter = int(argv[1])
    source = Path(argv[2])
    destination = Path(argv[3])
    destination.mkdir(parents=True, exist_ok=True)

    for line in (source / "series").read_text().splitlines():
        patch = line.strip()
        if not patch or patch.startswith("#"):
            continue
        src = source / patch
        dst = destination / f"{counter}_{Path(patch).name}"
        shutil.copy2(src, dst)
        counter += 1
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv))
