#!/usr/bin/python3

import sys
import subprocess
import os.path

if __name__ == '__main__':
    if len(sys.argv) not in (2,3):
        print(f"usage: {sys.argv[0]} [PDF] <TOPIC-PREFIX>")
        sys.exit(-1)

    pdf = sys.argv[1]
    pdf_base, _ = os.path.splitext(pdf)
    lecture = os.path.basename(pdf_base)
    if len(sys.argv) > 2:
        lecture = sys.argv[2]
    output_dir = f"build/html/{lecture}"

    if not os.path.exists(output_dir):
        os.mkdir(output_dir)

    # Use SVG
    convert = ["pdf2svg", pdf, f"{output_dir}/slide-%04d.svg", "all"]
    print("[split-pdf]", " ".join(convert))
    subprocess.check_call(convert)

