# Path: botnet/wrappers.py
# class ModuleWrapper(object):
#     """Wraps a module. It is used to hold a reference to a loaded module in the
#     Manager.
#     """
# 
#     def __init__(self, module):
#         self.module = module
#         self.name = get_ident_string(module.__class__)
#         self.logger = get_logger(str(self))
# 
#     def __repr__(self):
#         return '%s: %s' % (self.__class__.__name__, self.module)
# 
#     def start(self):
#         self.logger.debug('Start')
#         self.module.start()
# 
#     def stop(self):
#         self.logger.debug('Stop')
#         self.module.stop()


import threading
from .config import Config
from .logging import get_logger
from .modules.utils import get_module, reload_module, get_ident_string
from .signals import module_loaded, module_unloaded, module_load, module_unload, \
    _request_list_commands, _list_commands, config_changed, on_exception, \
    config_reload, config_reloaded
from .wrappers import ModuleWrapper
        except Exception as e:
            on_exception.send(self, e=e)

    def load_module_by_name(self, module_name):
        """Loads a module by name using the `modules.get_module` function."""
        try:
            module = get_module(module_name)
            reload_module(module)
            module_class = getattr(module, 'mod')
        except (ImportError, AttributeError) as e:
            raise ValueError('Could not import module %s.' % module_name) from e
        return self.load_module(module_class)

    def unload_module_by_name(self, module_name):
        """Unloads a module by name using the `modules.get_module` function."""
        try:
            module = get_module(module_name)
            module_class = getattr(module, 'mod')
        except (ImportError, AttributeError) as e:
            raise ValueError('Could not import module %s.' % module_name) from e
        return self.unload_module(module_class)

    def load_module(self, module_class):
        """Loads a module. Returns a wrapper containing a loaded module or None
        if the module was not loaded.
        """
        self.logger.debug('Load module %s', module_class)
        with self.wrappers_lock:
            if not self.get_wrapper(module_class):
                module = module_class(self.config)

# Path: botnet/wrappers.py
# class ModuleWrapper(object):
#     """Wraps a module. It is used to hold a reference to a loaded module in the
#     Manager.
#     """
# 
#     def __init__(self, module):
#         self.module = module
#         self.name = get_ident_string(module.__class__)
#         self.logger = get_logger(str(self))
# 
#     def __repr__(self):
#         return '%s: %s' % (self.__class__.__name__, self.module)
# 
#     def start(self):
#         self.logger.debug('Start')
#         self.module.start()
# 
#     def stop(self):
#         self.logger.debug('Stop')
#         self.module.stop()


# Path: botnet/manager.py
import threading
from .config import Config
from .logging import get_logger
from .modules.utils import get_module, reload_module, get_ident_string
from .signals import module_loaded, module_unloaded, module_load, module_unload, \
    _request_list_commands, _list_commands, config_changed, on_exception, \
    config_reload, config_reloaded
from .wrappers import ModuleWrapper

        except Exception as e:
            on_exception.send(self, e=e)

    def load_module_by_name(self, module_name):
        """Loads a module by name using the `modules.get_module` function."""
        try:
            module = get_module(module_name)
            reload_module(module)
            module_class = getattr(module, 'mod')
        except (ImportError, AttributeError) as e:
            raise ValueError('Could not import module %s.' % module_name) from e
        return self.load_module(module_class)

    def unload_module_by_name(self, module_name):
        """Unloads a module by name using the `modules.get_module` function."""
        try:
            module = get_module(module_name)
            module_class = getattr(module, 'mod')
        except (ImportError, AttributeError) as e:
            raise ValueError('Could not import module %s.' % module_name) from e
        return self.unload_module(module_class)

    def load_module(self, module_class):
        """Loads a module. Returns a wrapper containing a loaded module or None
        if the module was not loaded.
        """
        self.logger.debug('Load module %s', module_class)
        with self.wrappers_lock:
            if not self.get_wrapper(module_class):
                module = module_class(self.config)

                wrapper = ModuleWrapper(module)