Ejemplo n.º 1
0
    def load_plugin(self, plugin_name):
        """Load a plugin by name.

        :param str plugin_name:
            Name of the plugin to load.
        :return:
            Return the loaded plugin. Return ``None`` on failure.
        :rtype: Plugin
        """
        plugin = None
        self.log_message(
            self.translations['Loading'].get_string(plugin=plugin_name))
        try:
            plugin = self.manager.load(plugin_name)
        except InvalidPluginName:
            self.log_message(self.translations['Invalid Name'].get_string(
                plugin=plugin_name))
        except PluginAlreadyLoaded:
            self.log_message(self.translations['Already Loaded'].get_string(
                plugin=plugin_name))
        except PluginFileNotFoundError:
            self.log_message(self.translations['No Module'].get_string(
                plugin=plugin_name,
                file=GAME_PATH.relpathto(
                    self.manager.get_plugin_file_path(plugin_name)).replace(
                        '\\', '/')))
        except PluginHasBuiltInName:
            self.log_message(
                self.translations['Built-in'].get_string(plugin=plugin_name))
        except:
            except_hooks.print_exception()
            self.log_message(self.translations['Unable to Load'].get_string(
                plugin=plugin_name))
        else:
            self.log_message(self.translations['Successful Load'].get_string(
                plugin=plugin_name))

        return plugin
    def load_plugin(self, plugin_name):
        """Load a plugin by name.

        :param str plugin_name:
            Name of the plugin to load.
        :return:
            Return the loaded plugin. Return ``None`` on failure.
        :rtype: Plugin
        """
        plugin = None
        self.log_message(self.translations[
            'Loading'].get_string(plugin=plugin_name))
        try:
            plugin = self.manager.load(plugin_name)
        except InvalidPluginName:
            self.log_message(self.translations[
                'Invalid Name'].get_string(plugin=plugin_name))
        except PluginAlreadyLoaded:
            self.log_message(self.translations[
                'Already Loaded'].get_string(plugin=plugin_name))
        except PluginFileNotFoundError:
            self.log_message(self.translations[
                'No Module'].get_string(
                    plugin=plugin_name, file=GAME_PATH.relpathto(
                        self.manager.get_plugin_file_path(
                            plugin_name)).replace('\\', '/')))
        except PluginHasBuiltInName:
            self.log_message(self.translations[
                'Built-in'].get_string(plugin=plugin_name))
        except:
            except_hooks.print_exception()
            self.log_message(self.translations[
                'Unable to Load'].get_string(plugin=plugin_name))
        else:
            self.log_message(self.translations[
                'Successful Load'].get_string(plugin=plugin_name))

        return plugin