import os
import importlib


class ControllerLoader:
    """
    The ControllerLoader class.
    """

    @staticmethod
    def load(directory, package):
        """
        It is an utility to load automatically all the python
        module presents on a given directory
        """
        for module in os.listdir(directory):
            sub_dir = directory + "/" + module
            if os.path.isdir(sub_dir):
                ControllerLoader.load(sub_dir, "{}.{}".format(package, module))
            if module == "__init__.py" or module[-3:] != ".py":
                continue
            else:
                module_import_name = "{}.{}".format(package, module[:-3])
                importlib.import_module(module_import_name)

[((16, 22, 16, 43), 'os.listdir', 'os.listdir', ({(16, 33, 16, 42): 'directory'}, {}), '(directory)', False, 'import os\n'), ((18, 15, 18, 37), 'os.path.isdir', 'os.path.isdir', ({(18, 29, 18, 36): 'sub_dir'}, {}), '(sub_dir)', False, 'import os\n'), ((24, 16, 24, 59), 'importlib.import_module', 'importlib.import_module', ({(24, 40, 24, 58): 'module_import_name'}, {}), '(module_import_name)', False, 'import importlib\n')]