Пример #1
0
 def register_plugins(self, apps):
     """
     Register plugins - i.e. modules that have a KolibriPluginBase derived
     class in their kolibri_plugin.py module - these can be enabled and disabled
     by the Kolibri plugin machinery.
     """
     for app in apps:
         try:
             if app not in self._apps:
                 plugin_object = initialize_kolibri_plugin(app)
                 self._apps[app] = plugin_object
                 if is_plugin_updated(app):
                     config["UPDATED_PLUGINS"].add(app)
                     config.save()
         except (
             PluginDoesNotExist,
             MultiplePlugins,
             ImportError,
             HookSingleInstanceError,
             PluginLoadsApp,
         ) as e:
             logger.error("Cannot initialize plugin {}".format(app))
             logger.error(str(e))
             logger.error("Disabling plugin {}".format(app))
             config.clear_plugin(app)
             if isinstance(e, PluginLoadsApp):
                 logger.error(
                     "Please restart Kolibri now that this plugin is disabled"
                 )
                 raise
Пример #2
0
def disable_plugin(plugin_name):
    try:
        obj = initialize_kolibri_plugin(plugin_name)
        if obj:
            obj.disable()
            return True
    except Exception as e:
        logger.error(str(e))
        logger.warning(
            "Removing '{}' from configuration in a naive way.".format(
                plugin_name))
        config.clear_plugin(plugin_name)
        logger.info("Removed '{}'".format(plugin_name))
Пример #3
0
def autoremove_unavailable_plugins():
    """
    Sanitize INSTALLED_PLUGINS - something that should be done separately for all
    built in plugins, but we should not auto-remove plugins that are actually
    configured by the user or some other kind of hard dependency that should
    make execution stop if not loadable.
    """
    changed = False
    # Iterate over a copy of the set so that it is not modified during the loop
    for module_path in config["INSTALLED_PLUGINS"].copy():
        if not module_exists(module_path):
            config.clear_plugin(module_path)
            logger.error(
                ("Plugin {mod} not found and disabled. To re-enable it, run:\n"
                 "   $ kolibri plugin {mod} enable").format(mod=module_path))
            changed = True
    if changed:
        config.save()