Exemplo n.º 1
0
    def __init__(self, addon_name):
        '''Called when an addon's instance is initialized'''

        # Print message that the addon is going to be loaded
        AddonManagerLogger.log_message('[SP] ' + _addon_strings[
            'Loading'].get_string(addon=addon_name))

        # Get the addon's main file
        file_path = PLUGIN_PATH.joinpath(addon_name, addon_name + '.py')

        # Does the addon's main file exist?
        if not file_path.isfile():

            # Print a message that the addon's main file was not found
            AddonManagerLogger.log_message('[SP] ' + _addon_strings[
                'No Module'].get_string(addon=addon_name))

            # Raise an error, so that the addon
            # is not added to the AddonManager
            raise AddonFileNotFoundError

        # Import the addon
        self._addon = __import__(addon_name + '.' + addon_name)

        # Store the globals for the addon
        self._globals = self._addon.__dict__[addon_name].__dict__

        # Does the addon have a load function?
        if 'load' in self._globals:

            # Call the addon's load function
            self._globals['load']()
Exemplo n.º 2
0
    def __init__(self, plugin_name, base_import):
        """Called when a plugin's instance is initialized."""
        # Does the object have a logger set?
        if not hasattr(self, 'logger'):

            # If not, set the default logger
            self.logger = plugins_instance_logger

        # Does the object have a translations value set?
        if not hasattr(self, 'translations'):

            # If not, set the default translations
            self.translations = _plugin_strings

        # Print message that the plugin is going to be loaded
        self.logger.log_message(self.prefix +
                                self.translations['Loading'].get_string(
                                    plugin=plugin_name))

        # Get the plugin's main file
        file_path = PLUGIN_PATH.joinpath(*tuple(
            base_import.split('.')[:~0] + [plugin_name, plugin_name + '.py']))

        # Does the plugin's main file exist?
        if not file_path.isfile():

            # Print a message that the plugin's main file was not found
            self.logger.log_message(
                self.prefix + self.translations['No Module'].get_string(
                    plugin=plugin_name,
                    file=file_path.replace(GAME_PATH, '').replace('\\', '/')))

            # Raise an error so that the plugin
            # is not added to the PluginManager
            raise PluginFileNotFoundError

        # Get the base import
        import_name = base_import + plugin_name + '.' + plugin_name

        # Import the plugin
        self._plugin = import_module(import_name)

        # Set the globals value
        self._globals = {
            x: getattr(self._plugin, x)
            for x in dir(self._plugin)
        }
Exemplo n.º 3
0
    def __init__(self, plugin_name, base_import):
        """Called when a plugin's instance is initialized."""
        # Does the object have a logger set?
        if not hasattr(self, 'logger'):

            # If not, set the default logger
            self.logger = plugins_instance_logger

        # Does the object have a translations value set?
        if not hasattr(self, 'translations'):

            # If not, set the default translations
            self.translations = _plugin_strings

        # Print message that the plugin is going to be loaded
        self.logger.log_message(self.prefix + self.translations[
            'Loading'].get_string(plugin=plugin_name))

        # Get the plugin's main file
        file_path = PLUGIN_PATH.joinpath(*tuple(
            base_import.split('.')[:~0] + [plugin_name, plugin_name + '.py']))

        # Does the plugin's main file exist?
        if not file_path.isfile():

            # Print a message that the plugin's main file was not found
            self.logger.log_message(self.prefix + self.translations[
                'No Module'].get_string(
                plugin=plugin_name, file=file_path.replace(
                    GAME_PATH, '').replace('\\', '/')))

            # Raise an error so that the plugin
            # is not added to the PluginManager
            raise PluginFileNotFoundError

        # Get the base import
        import_name = base_import + plugin_name + '.' + plugin_name

        # Import the plugin
        self._plugin = import_module(import_name)

        # Set the globals value
        self._globals = {
            x: getattr(self._plugin, x) for x in dir(self._plugin)}
Exemplo n.º 4
0
    def plugins_directory(self):
        """Return the directory where the plugins are stored.

        :rtype: path.Path
        """
        return PLUGIN_PATH.joinpath(*tuple(self.base_import.split('.')[:~0]))
Exemplo n.º 5
0
    def plugins_directory(self):
        """Return the directory where the plugins are stored.

        :rtype: path.Path
        """
        return PLUGIN_PATH.joinpath(*tuple(self.base_import.split('.')[:~0]))
Exemplo n.º 6
0
    def __init__(self, plugin_name, base_import):
        '''Called when a plugin's instance is initialized'''

        # Does the object have a logger set?
        if not hasattr(self, 'logger'):

            # If not, set the default logger
            self.logger = PluginsInstanceLogger

        # Does the object have a translations value set?
        if not hasattr(self, 'translations'):

            # If not, set the default translations
            self.translations = _plugin_strings

        # Print message that the plugin is going to be loaded
        self.logger.log_message(self.prefix + self.translations[
            'Loading'].get_string(plugin=plugin_name))

        # Get the plugin's main file
        file_path = PLUGIN_PATH.joinpath(*tuple(
            base_import.split('.')[:~0] + [plugin_name, plugin_name + '.py']))

        # Does the plugin's main file exist?
        if not file_path.isfile():

            # Print a message that the plugin's main file was not found
            self.logger.log_message(self.prefix + self.translations[
                'No Module'].get_string(
                plugin=plugin_name, file=file_path.replace(
                    GAME_PATH, '').replace('\\', '/')))

            # Raise an error so that the plugin
            # is not added to the PluginManager
            raise PluginFileNotFoundError

        # Get the base import
        import_name = base_import + plugin_name + '.' + plugin_name

        # Import the plugin
        self._plugin = __import__(import_name)

        # Set the globals value
        self._globals = self._plugin.__dict__

        # Get the import name minus the first directory
        import_name = import_name.split('.', 1)[1]

        # Use "while" statement to find the proper globals for the plugin
        while '__path__' in self._globals:

            # Try to split the import path
            try:

                # Split the path by one level
                start, import_name = import_name.split('.', 1)

            # Are we at the end of the import?
            except ValueError:

                # Set the next value to the import name
                start = import_name

            # Set the globals value to the current module
            self._globals = self._globals[start].__dict__