def load_plugins(self, directory):
        plugins = {}
        sys.path.insert(0, directory)

        try:
            to_load = [p.strip() for p in self.config['porkchop']['plugins'].split(',')]
        except:
            to_load = []

        for infile in glob.glob(os.path.join(directory, '*.py')):
            module_name = os.path.splitext(os.path.split(infile)[1])[0]

            if os.path.basename(infile) == '__init__.py':
                continue
            if to_load and module_name not in to_load:
                continue

            try:
                module = imp.load_source(module_name, infile)
                for namek, klass in inspect.getmembers(module):
                    if inspect.isclass(klass) \
                       and issubclass(klass, PorkchopPlugin) \
                       and klass is not PorkchopPlugin:

                        if hasattr(klass, '__metric_name__'):
                            plugin_name = klass.__metric_name__
                        else:
                            plugin_name = module_name

                        plugins[plugin_name] = klass
                        plugins[plugin_name].config_file = os.path.join(
                            self.config_dir,
                            '%s.ini' % plugin_name
                        )

                        # Only one plugin per module.
                        break

            except __HOLE__:
                print 'Unable to load plugin %r' % infile
                import traceback
                traceback.print_exc()

        return plugins
dataset/ETHPy150Open disqus/porkchop/porkchop/plugin.py/PorkchopPluginHandler.load_plugins