def get_plugin_instance(plugin):
    try:
        source_path = os.path.join(plugin.path, plugin.script)
        cache.load_module(plugin.name, source_path)
        instance = cache.get_plugin(plugin.name)()
        return instance
    except:
        logger.error(traceback.format_exc())
        raise Exception("Error loading plugin module from %s" % source_path)
def get_plugin_instance(plugin):
    try:
        source_path = os.path.join(plugin.path, plugin.script)
        cache.load_module(plugin.name, source_path)
        instance = cache.get_plugin(plugin.name)()
        return instance
    except:
        logger.error(traceback.format_exc())
        raise Exception("Error loading plugin module from %s" % source_path)
Exemple #3
0
def get_info_from_script(name, script, context=None):
    from ion.plugin.loader import cache
    from ion.plugin.info import PluginInfo
    mod = cache.load_module(name, script)
    cls = cache.get_plugin(name)
    if not cls:
        return None
    plugin = cls()
    ## TODO plugin = cls(**context)
    info = PluginInfo.from_instance(plugin)
    return info
Exemple #4
0
def test_all_plugins():
    count = 0
    for m in cache.get_plugins():
        cls = cache.get_plugin(m)
        if not cls:
            continue
        log.info("Plugin Name: %s", m)
        count += 1
        yield check_plugin, cls
        yield run_plugin, cls
    assert count
Exemple #5
0
def test_all_plugins():
    count = 0
    for m in cache.get_plugins():
        cls = cache.get_plugin(m)
        if not cls:
            continue
        log.info("Plugin Name: %s", m)
        count += 1
        yield check_plugin, cls
        yield run_plugin, cls
    assert count
Exemple #6
0
def get_info_from_script(name, script, context=None):
    from ion.plugin.loader import cache
    from ion.plugin.info import PluginInfo
    mod = cache.load_module(name, script)
    cls = cache.get_plugin(name)
    if not cls:
        return None
    plugin = cls()
    ## TODO plugin = cls(**context)
    info = PluginInfo.from_instance(plugin)
    return info
Exemple #7
0
def get_info_from_script(name, script, context=None, add_to_store=True):
    from ion.plugin.loader import cache
    from ion.plugin.info import PluginInfo
    mod = cache.load_module(name, script, add_to_store)

    # if the load module command returned a None object, then lets raise an exception based on what happened
    if not mod:
        if name in cache.module_errors:
            raise cache.module_errors[name]
        else:
            raise Exception("Error loading the module.")

    cls = cache.get_plugin(name)
    if not cls:
        raise Exception("The python module loaded but no classes which extend 'IonPlugin' registered themselves with the framework.")
    plugin = cls()
    return PluginInfo.from_instance(plugin)
Exemple #8
0
def get_info_from_script(name, script, context=None, add_to_store=True):
    from ion.plugin.loader import cache
    from ion.plugin.info import PluginInfo
    mod = cache.load_module(name, script, add_to_store)

    # if the load module command returned a None object, then lets raise an exception based on what happened
    if not mod:
        if name in cache.module_errors:
            raise cache.module_errors[name]
        else:
            raise Exception("Error loading the module.")

    cls = cache.get_plugin(name)
    if not cls:
        raise Exception(
            "The python module loaded but no classes which extend 'IonPlugin' registered themselves with the framework."
        )
    plugin = cls()
    return PluginInfo.from_instance(plugin)
Exemple #9
0
def test_pluginscan():
    plugins = []
    d = os.path.dirname(__file__)
    for path in [
            os.path.join(d, '../../plugin'),
            os.path.join(d, '../../rndplugins')
    ]:
        path = os.path.normpath(os.path.abspath(path))
        if not os.path.exists(path):
            logger.debug("skipping '%s'", path)
            continue
        for (dirpath, dirnames, filenames) in os.walk(path):
            for name in dirnames:
                launchsh = os.path.join(dirpath, name, 'launch.sh')
                if os.path.exists(launchsh):
                    plugins.append((name, launchsh))
                    continue
                # Find all instances of PluginName/PluginName.py
                plugindef = os.path.join(dirpath, name, name + '.py')
                if os.path.exists(plugindef):
                    #sys.path.append(os.path.join(dirpath, name))
                    plugins.append((name, plugindef))

    logger.debug("Plugins: '%s'", plugins)

    cache.set_installed_modules(plugins)

    for (name, err) in cache.get_errors().iteritems():
        if err.__class__.__name__ == 'ImportError':
            logger.warn("Import Error [%s]: %s", name, err)
        else:
            logger.warn("Syntax Error [%s]: %s: %s", name,
                        err.__class__.__name__, err)

    for m in cache.get_plugins():
        cls = cache.get_plugin(m)
        if not cls:
            continue
        logger.info("Plugin Name: %s", m)
        yield check_plugin, cls
Exemple #10
0
def test_pluginscan():
    plugins = []
    d = os.path.dirname(__file__)
    for path in [os.path.join(d,'../../plugin'), os.path.join(d,'../../rndplugins') ]:
        path = os.path.normpath(os.path.abspath(path))
        if not os.path.exists(path):
            logger.debug("skipping '%s'", path)
            continue
        for (dirpath, dirnames, filenames) in os.walk(path):
            for name in dirnames:
                launchsh = os.path.join(dirpath, name, 'launch.sh')
                if os.path.exists(launchsh):
                    plugins.append( (name, launchsh) )
                    continue
                # Find all instances of PluginName/PluginName.py
                plugindef = os.path.join(dirpath, name, name + '.py')
                if os.path.exists(plugindef):
                    #sys.path.append(os.path.join(dirpath, name))
                    plugins.append( (name, plugindef) )

    logger.debug("Plugins: '%s'", plugins)

    cache.set_installed_modules(plugins)

    for (name, err) in cache.get_errors().iteritems():
        if err.__class__.__name__ == 'ImportError':
            logger.warn("Import Error [%s]: %s", name, err)
        else:
            logger.warn("Syntax Error [%s]: %s: %s", name, err.__class__.__name__, err)

    for m in cache.get_plugins():
        cls = cache.get_plugin(m)
        if not cls:
            continue
        logger.info("Plugin Name: %s", m)
        yield check_plugin, cls
Exemple #11
0
def unzipPlugin(zipfile, logger=None):
    if not logger:
        logger = logging.getLogger(__name__)
    ## Extract plugin to scratch folder. When complete, move to final location.
    plugin_path, ext = os.path.splitext(zipfile)
    plugin_name = os.path.basename(plugin_path)

    # ZIP file must named with plugin name - fragile
    # FIXME - handle (1) additions (common for multiple downloads via browser)
    # FIXME - handle version string in ZIP archive name

    scratch_path = os.path.join(settings.PLUGIN_PATH, "scratch",
                                "install-temp", plugin_name)
    (prefix, files) = extract_zip(zipfile,
                                  scratch_path,
                                  auto_prefix=True,
                                  logger=logger)
    if prefix:
        plugin_name = os.path.basename(prefix)

    plugin_temp_home = os.path.join(scratch_path, prefix)
    try:
        # Convert script into PluginClass, get info by introspection
        from iondb.plugins.manager import pluginmanager
        script, islaunch = pluginmanager.find_pluginscript(
            plugin_temp_home, plugin_name)
        logger.debug("Got script: %s", script)
        from ion.plugin.loader import cache
        ret = cache.load_module(plugin_name, script)
        cls = cache.get_plugin(plugin_name)
        p = cls()
        final_name = p.name  # what the plugin calls itself, regardless of ZIP file name
        logger.info("Plugin calls itself: '%s'", final_name)
    except:
        logger.exception("Unable to interrogate plugin name from: '%s'",
                         zipfile)
        final_name = plugin_name

    #move to the plugin dir
    # New extract_zip removes prefix from extracted files.
    # But still writes to file_name
    try:
        final_install_dir = os.path.join(settings.PLUGIN_PATH, final_name)
        if os.path.exists(final_install_dir) and (final_install_dir !=
                                                  settings.PLUGIN_PATH):
            logger.info("Deleting old copy of plugin at '%s'",
                        final_install_dir)
            delete_that_folder(
                final_install_dir,
                "Error Deleting old copy of plugin at '%s'" %
                final_install_dir)
        parent_folder = os.path.dirname(final_install_dir)
        if not os.path.exists(parent_folder):
            logger.info("Creating path for plugin '%s' for '%s'",
                        parent_folder, final_install_dir)
            os.makedirs(parent_folder, 0555)

        logger.info(
            "Moving plugin from temp extract folder '%s' to final location: '%s'",
            plugin_temp_home, final_install_dir)
        shutil.move(plugin_temp_home, final_install_dir)
        delete_that_folder(scratch_path,
                           "Deleting plugin install scratch folder")
    except (IOError, OSError):
        logger.exception(
            "Failed to move plugin from temp extract folder '%s' to final location: '%s'",
            plugin_temp_home, final_install_dir)
        raise

    # Now that it has been downloaded,
    # convert pre-plugin into real db plugin object
    try:
        from iondb.plugins.manager import pluginmanager
        (new_plugin, updated) = pluginmanager.install(final_name,
                                                      final_install_dir)
    except ValueError:
        logger.exception("Failed to install plugin")
        #delete_that_folder(final_install_dir)

    return {
        "plugin": final_name,
        "path": final_install_dir,
        "files": files,
    }
Exemple #12
0
def unzipPlugin(zipfile, logger=None):
    if not logger:
        logger = logging.getLogger(__name__)
    ## Extract plugin to scratch folder. When complete, move to final location.
    plugin_path, ext = os.path.splitext(zipfile)
    plugin_name = os.path.basename(plugin_path)

    # ZIP file must named with plugin name - fragile
    # FIXME - handle (1) additions (common for multiple downloads via browser)
    # FIXME - handle version string in ZIP archive name

    scratch_path = os.path.join(settings.PLUGIN_PATH,"scratch","install-temp",plugin_name)
    (prefix, files) = extract_zip(zipfile, scratch_path, auto_prefix=True, logger=logger)
    if prefix:
        plugin_name = os.path.basename(prefix)

    plugin_temp_home = os.path.join(scratch_path, prefix)
    try:
        # Convert script into PluginClass, get info by introspection
        from iondb.plugins.manager import pluginmanager
        script, islaunch = pluginmanager.find_pluginscript(plugin_temp_home, plugin_name)
        logger.debug("Got script: %s", script)
        from ion.plugin.loader import cache
        ret = cache.load_module(plugin_name, script)
        cls = cache.get_plugin(plugin_name)
        p = cls()
        final_name = p.name # what the plugin calls itself, regardless of ZIP file name
        logger.info("Plugin calls itself: '%s'", final_name)
    except:
        logger.exception("Unable to interrogate plugin name from: '%s'", zipfile)
        final_name = plugin_name

    #move to the plugin dir
    # New extract_zip removes prefix from extracted files.
    # But still writes to file_name
    try:
        final_install_dir =  os.path.join(settings.PLUGIN_PATH, final_name)
        if os.path.exists(final_install_dir) and (final_install_dir != settings.PLUGIN_PATH):
            logger.info("Deleting old copy of plugin at '%s'", final_install_dir)
            delete_that_folder(final_install_dir, "Error Deleting old copy of plugin at '%s'" % final_install_dir)
        parent_folder = os.path.dirname(final_install_dir)
        if not os.path.exists(parent_folder):
            logger.info("Creating path for plugin '%s' for '%s'", parent_folder, final_install_dir)
            os.makedirs(parent_folder, 0555)

        logger.info("Moving plugin from temp extract folder '%s' to final location: '%s'", plugin_temp_home, final_install_dir)
        shutil.move(plugin_temp_home, final_install_dir)
        delete_that_folder(scratch_path, "Deleting plugin install scratch folder")
    except (IOError, OSError):
        logger.exception("Failed to move plugin from temp extract folder '%s' to final location: '%s'", plugin_temp_home, final_install_dir)
        raise

    # Now that it has been downloaded,
    # convert pre-plugin into real db plugin object
    try:
        from iondb.plugins.manager import pluginmanager
        (new_plugin, updated) = pluginmanager.install(final_name, final_install_dir)
    except ValueError:
        logger.exception("Failed to install plugin")
        #delete_that_folder(final_install_dir)

    return {
        "plugin": final_name,
        "path": final_install_dir,
        "files": files,
    }