def _add_plugin(self, plugindir):
        """
        If this is a Jig plugin, add it.

        ``plugindir`` should be the full path to a directory containing all the
        files required for a jig plugin.
        """
        # Is this a plugins?
        config_filename = join(plugindir, PLUGIN_CONFIG_FILENAME)

        if not isfile(config_filename):
            raise PluginError('The plugin file {0} is missing.'.format(
                config_filename))

        config = SafeConfigParser()

        with open(config_filename, 'r') as fh:
            try:
                config.readfp(fh)
            except ConfigParserError as e:
                raise PluginError(e)

        try:
            settings = OrderedDict(config.items('settings'))
        except NoSectionError:
            settings = []

        try:
            plugin_info = OrderedDict(config.items('plugin'))
        except NoSectionError:
            raise PluginError(
                'The plugin config does not contain a '
                '[plugin] section.')

        try:
            bundle = plugin_info['bundle']
            name = plugin_info['name']
        except __HOLE__:
            raise PluginError(
                'Could not find the bundle or name of '
                'the plugin.')

        new_section = 'plugin:{bundle}:{name}'.format(
            bundle=bundle, name=name)

        if self.config.has_section(new_section):
            raise PluginError('The plugin is already installed.')

        self.config.add_section(new_section)

        self.config.set(new_section, 'path', plugindir)

        for setting in settings:
            option, value = setting, settings[setting]
            self.config.set(new_section, option, value)

        # Re-initialize the self.plugins list
        self._plugins = self._init_plugins(self.config)

        # And return the plugin once we find it
        for plugin in self._plugins:   # pragma: no branch
            if plugin.name == name and plugin.bundle == bundle:
                return plugin
dataset/ETHPy150Open robmadole/jig/src/jig/plugins/manager.py/PluginManager._add_plugin