Subversion Repositories MeX

Rev

Rev 1 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
# File: srv_plugins.py
# Author: Tomás Vírseda
# License: GPL v3
# Description: Plugin Manager service
"""



from mex.core.mod_srv import Service
from mex.core.mod_env import GPATH, LPATH, APP
from yapsy.PluginManager import PluginManager
from yapsy.IPlugin import IPlugin

class IMetadataPlugin(IPlugin):
    pass

class MexPluginManager(Service):
    def initialize(self):
        self.log.debug("Loading Plugin Manager")
        self.manager = PluginManager()

        # set plugins paths
        self.manager.setPluginPlaces([GPATH['PLUGINS'], LPATH['PLUGINS']])

        # allow only plugins belonging to the Metadata category
        self.manager.setCategoriesFilter({
            "Metadata" : IMetadataPlugin,
            "Default" : IPlugin,
        })

        # Get all
        self.manager.collectPlugins()
        self.log.debug("Number of plugins found: %d" % len(self.manager.getAllPlugins()))
        # ~ for plugin in self.manager.getAllPlugins():
            # ~ self.log.debug("\tCategory: %s - Name: %s" % (plugin.category, plugin.name))
        # ~ plugin.plugin_object.print_name()


    def get_manager(self):
        return self.manager

    def get_plugins(self):
        return self.manager.getAllPlugins()

    def get_plugins_by_category(self, category):
        try:
            return self.manager.getPluginsOfCategory(category)
        except:
            self.log.warning("Plugin category '%s' doesn't exist" % category)
            return []