Exemplo n.º 1
0
    def reload_plugins(prefix = None):
        """
Reload all plugins or the plugins matching the given prefix.

:param prefix: Plugin prefix

:return: (bool) True on success
:since:  v0.2.00
        """

        # pylint: disable=broad-except, no-member

        _return = True

        for package in Manager._plugins:
            if (prefix is None or package.startswith("{0}.".format(prefix))):
                modules = (Manager._plugins[package].copy()
                           if (hasattr(Manager._plugins[package], "copy")) else
                           copy(Manager._plugins[package])
                          )

                if (_mode == _MODE_IMPORT_MODULE
                    and hasattr(importlib, "invalidate_caches")
                   ): importlib.invalidate_caches()

                for module_name in modules:
                    try:
                        module = NamedLoader._get_module(module_name)

                        if (module is not None and hasattr(module, "unregister_plugin")): module.unregister_plugin()

                        try: reload(module)
                        except Exception: Manager._plugins[package].remove(module_name)

                        if (module is not None and hasattr(module, "on_plugin_reloaded")): module.on_plugin_reloaded()
                    except Exception as handled_exception:
                        if (Manager._log_handler is not None): Manager._log_handler.error(handled_exception, context = "pas_plugins")
                        _return = False
                    #
                #

                package_prefix = (package[:package.rindex(".")] if (prefix is None) else prefix)
                package_plugin = package[1 + package.rindex("."):]

                Manager.load_plugin(package_plugin, package_prefix)
            #
        #

        return _return