示例#1
0
    def _load(plugin):
        """
        Import a module by file name.
        :param plugin: A plugin to load.
        :type plugin: Plugin
        :return: The loaded plugin.
        :rtype: Plugin
        """
        Remote.clear()
        Actions.clear()
        Plugin.add(plugin)
        try:
            path = plugin.descriptor.main.plugin
            if path:
                Plugin.add(plugin, path)
                plugin.impl = __import__(path, {}, {}, [path.split('.')[-1]])
            else:
                path = PluginLoader._find(plugin.name)
                plugin.impl = imp.load_source(plugin.name, path)

            log.info('plugin:%s loaded using: %s', plugin.name, path)

            for fn in Remote.find(plugin.impl.__name__):
                fn.gofer.plugin = plugin

            plugin.dispatcher += Remote.collated()
            plugin.actions = Actions.collated()
            plugin.delegate = Delegate()
            plugin.load()
            return plugin
        except Exception:
            log.exception('plugin:%s, import failed', plugin.name)
            Plugin.delete(plugin)
示例#2
0
 def test_init(self):
     Delegate.load.append(1)
     Delegate.unload.append(2)
     d = Delegate()
     self.assertEqual(Delegate.load, [])
     self.assertEqual(Delegate.unload, [])
     self.assertEqual(d.load, [1])
     self.assertEqual(d.unload, [2])
示例#3
0
 def __init__(self, descriptor, path):
     """
     :param descriptor: The plugin descriptor.
     :type descriptor: PluginDescriptor
     :param path: The plugin descriptor path.
     :type path: str
     """
     self.__mutex = RLock()
     self.path = path
     self.descriptor = descriptor
     self.pool = ThreadPool(int(descriptor.main.threads or 1))
     self.impl = None
     self.actions = []
     self.dispatcher = Dispatcher()
     self.whiteboard = Whiteboard()
     self.scheduler = Scheduler(self)
     self.delegate = Delegate()
     self.authenticator = None
     self.consumer = None
示例#4
0
 def test_unloaded_failed(self):
     d = Delegate()
     d.unload = [Mock(side_effect=ValueError), Mock()]
     d.unloaded()
     for fn in d.unload:
         fn.asssert_called_once_with()
示例#5
0
 def test_unloaded(self):
     d = Delegate()
     d.unload = [Mock(), Mock()]
     d.unloaded()
     for fn in d.unload:
         fn.asssert_called_once_with()