def scan_for_plugins():
    """Look through plugin directory for any directory with a file named
    "bpplugin.json". Fill in an plugin object, and pass to _run_count_plugin to
    handle lifetime.

    """
    for i in os.listdir(config.get_dir("plugin")):
        plugin_file = os.path.join(config.get_dir("plugin"), i,
                                   Plugin.PLUGIN_INFO_FILE)
        if not os.path.exists(plugin_file):
            continue
        info = None
        try:
            with open(plugin_file) as pfile:
                info = json.load(pfile)
        except ValueError:
            logging.warning("JSON configuration not valid for plugin %s!", i)
            continue
        if not set(Plugin.PLUGIN_REQUIRED_KEYS).issubset(set(info.keys())):
            raise PluginException("Invalid Plugin")
        if info["name"] in _plugins.keys():
            raise PluginException("Plugin Collision! Two plugins named " +
                                  info["name"])
        greenlet.spawn_gevent_func("run_count_plugin: %s" % info["name"],
                                   "plugin", _run_count_plugin, Plugin(info, i))
dataset/ETHPy150Open metafetish/buttplug/buttplug/core/plugin.py/scan_for_plugins/original