#!/usr/bin/env python
import inspect
import os
import pkgutil
import sys

import pylero

# On import, the (gnu/)readline features are active without calling
# any functions. This enables the arrow keys. Without this
# import, pressing the arrow keys shows ctrl chars.
if sys.version_info > (3, 6):
    try:
        import gnureadline as readline
    except ImportError:
        # `readline` is deprecated and `gnureadline` requires `Python.h` and
        # `ncurses-devel` packages. TODO: Furnish steps to install `gnureadline`
        pass
else:
    # `readline` on python > 3.6 resulting in Traceback at times
    import readline


def main():
    EXCLUDE_MODULES = ["test_classes", "embedding", "interface", "server", "session"]
    _class_names = []
    for lstmods in pkgutil.iter_modules([pylero.__path__[0]]):
        the_mod = lstmods[1]
        if the_mod not in EXCLUDE_MODULES:
            imp_mod = __import__("pylero.{0}".format(the_mod), fromlist=[""])
        for cls in inspect.getmembers(imp_mod, inspect.isclass):
            globals()[cls[0]] = cls[1]
            if cls[0] not in _class_names:
                _class_names.append(cls[0])
    _class_names.sort()


if __name__ == "__main__":
    main()
    os.environ["PYTHONINSPECT"] = "yes"
