#!/usr/bin/env python3

import pathlib

header = (
    pathlib.Path(__file__).parent / ".." / "include" / "libtorrent_alerts.h"
).open("w+")

f = (
    pathlib.Path(__file__).parent
    / ".."
    / ".."
    / ".."
    / "include"
    / "libtorrent"
    / "alert_types.hpp"
).open()

header.write("""// generated by tools/gen_alert_header.py

#ifndef LIBTORRENT_ALERTS_H
#define LIBTORRENT_ALERTS_H

// alert types
enum alert_types_t {
""")

for line in f:
    line = line.strip()

    if "#define" in line:
        continue

    if "TORRENT_DEFINE_ALERT(" not in line and "TORRENT_DEFINE_ALERT_PRIO(" not in line:
        continue

    args = line.split("(")[1].split(")")[0].split(",")
    args[0] = args[0].replace("_alert", "")

    header.write("\tALERT_%s = %s,\n" % (args[0].upper(), args[1]))

header.write("""};

#endif // LIBTORRENT_ALERTS_H
""")
