Example #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
Example #2
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()
Example #3
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 (MultiplePlugins, ImportError):
             logger.warn("Cannot initialize plugin {}".format(app))
         except PluginDoesNotExist:
             pass
Example #4
0
def enable_new_default_plugins():
    """
    Enable new plugins that have been added between versions
    This will have the undesired side effect of reactivating
    default plugins that have been explicitly disabled by a user,
    in versions prior to the implementation of a plugin blacklist.
    """
    changed = False
    for module_path in DEFAULT_PLUGINS:
        if module_path not in config["INSTALLED_PLUGINS"]:
            config["INSTALLED_PLUGINS"].add(module_path)
            # Can be migrated to upgrade only logic
            if module_path not in config["DISABLED_PLUGINS"]:
                logger.warning((
                    "Default plugin {mod} not found in configuration. To re-disable it, run:\n"
                    "   $ kolibri plugin {mod} disable").format(
                        mod=module_path))
            changed = True

    if changed:
        config.save()