Ejemplo n.º 1
0
def load(name):
    ''' Load a plugin. '''
    try:
        if name in active_plugins:
            return False, 'Plugin %s already loaded' % name
        descr  = plugin_descriptions.get(name)
        if not descr:
            return False, 'Error loading plugin: plugin %s not found.' % name
        # Load the plugin
        mod    = imp.find_module(descr.module_name, [descr.module_path])
        plugin = imp.load_module(descr.module_name, *mod)
        # Initialize the plugin
        config, stackfuns    = plugin.init_plugin()
        active_plugins[name] = plugin
        dt     = max(config.get('update_interval', 0.0), bs.sim.simdt)
        prefun = config.get('preupdate')
        updfun = config.get('update')
        rstfun = config.get('reset')
        if prefun:
            preupdate_funs[name] = [bs.sim.simt + dt, dt, prefun]
        if updfun:
            update_funs[name]    = [bs.sim.simt + dt, dt, updfun]
        if rstfun:
            reset_funs[name]     = rstfun
        # Add the plugin's stack functions to the stack
        bs.stack.append_commands(stackfuns)
        # Add the plugin as data parent to the variable explorer
        ve.register_data_parent(plugin, name.lower())
        return True, 'Successfully loaded plugin %s' % name
    except ImportError as e:
        print('BlueSky plugin system failed to load', name, ':', e)
        return False, 'Failed to load %s' % name
Ejemplo n.º 2
0
def load(name):
    ''' Load a plugin. '''
    try:
        if name in active_plugins:
            return False, 'Plugin %s already loaded' % name
        descr = plugin_descriptions.get(name)
        if not descr:
            return False, 'Error loading plugin: plugin %s not found.' % name
        # Load the plugin
        mod = imp.find_module(descr.module_name, [descr.module_path])
        plugin = imp.load_module(descr.module_name, *mod)
        # Initialize the plugin
        config, stackfuns = plugin.init_plugin()
        active_plugins[name] = plugin
        dt = max(config.get('update_interval', 0.0), bs.sim.simdt)
        prefun = config.get('preupdate')
        updfun = config.get('update')
        rstfun = config.get('reset')
        if prefun:
            preupdate_funs[name] = [bs.sim.simt + dt, dt, prefun]
        if updfun:
            update_funs[name] = [bs.sim.simt + dt, dt, updfun]
        if rstfun:
            reset_funs[name] = rstfun
        # Add the plugin's stack functions to the stack
        bs.stack.append_commands(stackfuns)
        # Add the plugin as data parent to the variable explorer
        ve.register_data_parent(plugin, name.lower())
        return True, 'Successfully loaded plugin %s' % name
    except ImportError as e:
        print('BlueSky plugin system failed to load', name, ':', e)
        return False, 'Failed to load %s' % name