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)

[((307, 328), 'os.listdir', 'os.listdir', (['directory'], {}), '(directory)\n', (317, 328), False, 'import os\n'), ((392, 414), 'os.path.isdir', 'os.path.isdir', (['sub_dir'], {}), '(sub_dir)\n', (405, 414), False, 'import os\n'), ((693, 736), 'importlib.import_module', 'importlib.import_module', (['module_import_name'], {}), '(module_import_name)\n', (716, 736), False, 'import importlib\n')]