#!/usr/bin/env python3

import pathlib
import re


def process(dn):

    required = set()

    for fn in dn.glob("**/*.pyx"):

        contents = fn.read_text()

        for m in re.finditer(r'gl[A-Z]\w+', fn.read_text()):

            required.add(m.group(0))

    required = list(required)
    required.sort()

    with open(dn / (str(dn.name) + "functions.py"), "w") as f:
        print("""\
# This file has been automatically generated by module/uguu/generate_required_functions.py,
# please do not edit it by hand.

from __future__ import division, absolute_import, with_statement, print_function, unicode_literals
from renpy.compat import *

required_functions = [""", file=f)

        for i in required:
            print(f'    "{i}",', file=f)

        print("""\
]""", file=f)






if __name__ == "__main__":
    p = pathlib.Path(__file__)

    process(p.parent / "../../renpy/gl")
    process(p.parent / "../../renpy/gl2")
