Exemplo n.º 1
0
def create_awsume_plugin_manager(pluginPath):
    """
    create the plugin manager and register all available categories of plugins
    """
    manager = PluginManager.PluginManager()
    locate_plugins(manager, pluginPath)
    manager.collectPlugins()
    return manager
Exemplo n.º 2
0
 def __init__(self, plugin_dir, plugin_ext):
     plg_analyzer = PluginFileLocator.PluginFileAnalyzerWithInfoFile(
         'locator', plugin_ext)
     plg_locator = PluginFileLocator.PluginFileLocator(
         analyzers=[plg_analyzer])
     self.plugin_manager = PluginManager.PluginManager(
         categories_filter=PLUGIN_CATEGORIES,
         directories_list=[plugin_dir],
         plugin_locator=plg_locator)
Exemplo n.º 3
0
def main():
    manager = PluginManager.PluginManager()
    manager.setPluginPlaces(['plugins'])
    manager.collectPlugins()

    plugins = manager.getAllPlugins()
    for plugin in plugins:
        print(plugin, type(plugin))
        print(plugin.plugin_object, type(plugin.plugin_object))
        print(plugin.plugin_object.name)
Exemplo n.º 4
0
def initialize_plugins(pav_cfg):
    """Initialize the plugin system, and activate plugins in all known plugin
    directories (except those specifically disabled in the config. Should
    only ever be run once pavilion command.
    :param pav_cfg: The pavilion configuration
    :return: Nothing
    :raises PluginError: When there's an issue with a plugin or the plugin
        system in general.
    :raises RuntimeError: When you try to run this twice.
    """

    global _PLUGIN_MANAGER  # pylint: disable=W0603

    if _PLUGIN_MANAGER is not None:
        LOGGER.warning("Tried to initialize plugins multiple times.")
        return

    # Always look here for plugins
    plugin_dirs = [Path(__file__).parent.as_posix()]
    # And in all the user provided plugin directories.
    for cfg_dir in pav_cfg.config_dirs:
        plugin_dirs.append((cfg_dir / 'plugins').as_posix())

    try:
        pman = PluginManager.PluginManager(directories_list=plugin_dirs,
                                           categories_filter=PLUGIN_CATEGORIES)

        pman.collectPlugins()
    except Exception as err:
        raise PluginError("Error initializing plugin system: {}".format(err))

    # Activate each plugin in turn.
    for plugin in pman.getAllPlugins():
        plugin_dot_name = '{p.category}.{p.name}'.format(p=plugin)

        if plugin_dot_name in pav_cfg.disable_plugins:
            # Don't initialize these plugins.
            continue

        try:
            plugin.plugin_object.activate()
        except Exception as err:
            raise PluginError("Error activating plugin {name}: {err}".format(
                name=plugin.name, err=err))

    # Some plugin types have core plugins that are built-in.
    for _, cat_obj in PLUGIN_CATEGORIES.items():
        module = inspect.getmodule(cat_obj)
        if hasattr(module, 'register_core_plugins'):
            module.register_core_plugins()

    _PLUGIN_MANAGER = pman
Exemplo n.º 5
0
def initialize_plugins(pav_cfg):
    """Initialize the plugin system, and activate plugins in all known plugin
    directories (except those specifically disabled in the config. Should
    only ever be run once pavilion command.
    :param pav_cfg: The pavilion configuration
    :return: Nothing
    :raises PluginError: When there's an issue with a plugin or the plugin
        system in general.
    :raises RuntimeError: When you try to run this twice.
    """

    global _PLUGIN_MANAGER  # pylint: disable=W0603

    if _PLUGIN_MANAGER is not None:
        LOGGER.warning("Tried to initialize plugins multiple times.")
        return

    plugin_dirs = [
        str(Path(cfg_dir) / 'plugins') for cfg_dir in pav_cfg.config_dirs
    ]

    try:
        pman = PluginManager.PluginManager(directories_list=plugin_dirs,
                                           categories_filter=PLUGIN_CATEGORIES)

        pman.locatePlugins()
        pman.collectPlugins()
    except Exception as err:
        raise PluginError("Error initializing plugin system: {}".format(err))

    # Activate each plugin in turn.
    for plugin in pman.getAllPlugins():
        plugin_dot_name = '{p.category}.{p.name}'.format(p=plugin)

        if plugin_dot_name in pav_cfg.disable_plugins:
            # Don't initialize these plugins.
            continue

        try:
            plugin.plugin_object.activate()
        except Exception as err:
            raise PluginError("Error activating plugin {name}: {err}".format(
                name=plugin.name, err=err))

    _PLUGIN_MANAGER = pman
Exemplo n.º 6
0
    def plugins_init(self, is_reloading=False):
        # Disable DEBUG logging of yapsy
        logging.getLogger('yapsy').setLevel(logging.WARNING)

        if is_reloading:
            logging.info("Deactivating All Plugins")
            for pluginInfo in self.pm.getAllPlugins():
                self.pm.deactivatePluginByName(pluginInfo.name)
        route = get_route()
        self.pm = PluginManager.PluginManager(directories_list=[os.path.join(route, "plugins")],)

        self.pm.collectPlugins()
        for pluginInfo in self.pm.getAllPlugins():
            ## This stops the plugins marked as Disabled from being activated.
            if (not pluginInfo.details.has_option("Core", "Disabled")):
                plugin_name = pluginInfo.name
                self.pm.activatePluginByName(plugin_name)
                self.add_plugin_name_on_module_dropdown(plugin_name)
                logging.info("Plugin {0} activated".format(plugin_name))
        ## Setting AYAB as the default value
        ## TODO: better way of setting ayab as default plugin.
        self.set_enabled_plugin("AYAB")
Exemplo n.º 7
0
class KbExtractorPluginManager(object):
    """Plugin manager for the KB Extractor.

    """

    def __init__(self):
        self.manager = PluginManager()

    def load_plugins(self):
        """Loads the plugins from the plugin directories.

        """
        # Locate the current directory
        current_directory = os.path.abspath(os.path.dirname(__file__))

        # Create the list of folders containing the plugins
        plugin_directories = ["plugins", "plugins/sources",
                              "plugins/destinations"]

        # Create the full path out of it
        places = []
        [places.append(os.path.join(current_directory, directory)) for
         directory in plugin_directories]

        # Set the plugin locations
        self.manager.setPluginPlaces(places)

        # Set the categories
        self.manager.setCategoriesFilter(
            {"Destination": IDestinationPlugin, "Source": ISourcePlugin})
        self.manager.collectPlugins()

    def show_all(self):
        """Displays the name and the description of each plugin.

        """

        # Sort the plugins by category
        plugins = {}

        # Go through all the plugins
        for plugin in self.manager.getAllPlugins():
            # Retrieve the plugin category
            category = plugins.get(plugin.category)

            # Create the category in the dictionary if it does not exist
            if not category:
                plugins[plugin.category] = []

            # Add the plugin to the right category
            plugins[plugin.category].append(plugin)

        # Go through all the categories
        for category in plugins:
            # Print the name of the category
            print("[{0}]".format(category))

            # Print the plugin information
            for plugin_info in plugins[category]:
                print("   {0}: {1}".format(plugin_info.name,
                                           plugin_info.description))
Exemplo n.º 8
0
 def __init__(self):
     self.manager = PluginManager()