示例#1
0
    def _load_auth(self, provider):
        '''Loads the given provider'''

        # Send a message that the auth provider is being loaded
        AuthManagerLogger.log_message(
            '[SP Auth] ' + _auth_strings[
                'Loading'].get_string(provider=provider))

        # Is the provider loaded?
        if provider in self:

            # If so, send a message that the provider is already loaded
            AuthManagerLogger.log_message(
                '[SP Auth] ' + _auth_strings[
                    'Already Loaded'].get_string(provider=provider))

            # No need to go further
            return

        # Does the provider's file exist?
        if not AUTH_PROVIDER_PATH.joinpath(provider + '.py').isfile():

            # Send a message that the file does not exist
            AuthManagerLogger.log_message(
                '[SP Auth] ' + _auth_strings[
                    'No Module'].get_string(provider=provider))

            # No need to go further
            return

        # Attempt to load the provider
        self[provider] = __import__(
            'auth.providers.{0}'.format(provider), fromlist=[''])

        # Call the provider's load function
        self[provider].load()

        # Send a message that the provider was loaded
        AuthManagerLogger.log_message(
            '[SP Auth] ' + _auth_strings[
                'Load Successful'].get_string(provider=provider))
示例#2
0
#   Paths
from paths import GAME_PATH
from paths import CFG_PATH
#   Translations
from translations.strings import LangStrings

# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the core settings language strings
_core_strings = LangStrings('_core/core_settings_strings')

# Get a list of auth providers
_auth_providers = [
    provider.namebase
    for provider in AUTH_PROVIDER_PATH.files() + AUTH_PROVIDER_PATH.dirs()
    if not provider.namebase.startswith('__')
]

# Get the sp.core.settings logger
core_settings_logger = core_logger.settings


# =============================================================================
# >> CLASSES
# =============================================================================
class _CoreSettings(ConfigObj):
    """Class used to store core settings."""
    def __init__(self, infile):
        """Add missing items and set comments using the server's language."""
        # Import the file
示例#3
0
    def load_auth(self, provider):
        '''Loads the given provider'''

        # Send a message that the auth provider is being loaded
        AuthManagerLogger.log_message(
            '[SP Auth] ' + _auth_strings[
                'Loading'].get_string(provider=provider))

        # Is the provider loaded?
        if provider in self:

            # If so, send a message that the provider is already loaded
            AuthManagerLogger.log_message(
                '[SP Auth] ' + _auth_strings[
                    'Already Loaded'].get_string(provider=provider))

            # No need to go further
            return

        # Does the provider's file exist?
        if not AUTH_PROVIDER_PATH.joinpath(provider + '.py').isfile():

            # Send a message that the file does not exist
            AuthManagerLogger.log_message(
                '[SP Auth] ' + _auth_strings[
                    'No Module'].get_string(provider=provider))

            # No need to go further
            return

        # Import the provider's module
        module = __import__(
            'auth.providers.{0}'.format(provider), fromlist=[''])

        # Loop through all objects in the module
        for module_object in dir(module):

            # Get the object's instance
            instance = getattr(module, module_object)

            # Is the current object a AuthBase instance?
            if isinstance(instance, AuthBase):

                # Found the instance
                break

        # Was no AuthBase instance found?
        else:

            # Raise an error that the object was not found
            raise NotImplementedError(
                'No AuthBase instance found in provider'
                ' "{0}"'.format(provider))

        # Attempt to call the provider's load function
        instance.load()

        # Add the provider to the dictionary
        self[provider] = instance

        # Send a message that the provider was loaded
        AuthManagerLogger.log_message(
            '[SP Auth] ' + _auth_strings[
                'Load Successful'].get_string(provider=provider))
示例#4
0
# =============================================================================
# >> ALL DECLARATION
# =============================================================================
# Set all to an empty list
__all__ = []


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the core settings language strings
_core_strings = LangStrings('_core/core_settings_strings')

# Get a list of auth providers
_auth_providers = [
    provider.namebase for provider in AUTH_PROVIDER_PATH.files() +
    AUTH_PROVIDER_PATH.dirs() if not provider.namebase.startswith('__')]

# Get the sp._core.settings logger
_CoreSettingsLogger = _CoreLogger.settings


# =============================================================================
# >> CLASSES
# =============================================================================
class _SettingsMeta(type):
    '''Metaclass used to store methods in order of creation'''

    @classmethod
    def __prepare__(mcl, name, bases):
        '''Returns an ordered dictionary'''
示例#5
0
    def load_auth(self, provider):
        """Load the given provider."""
        # Send a message that the auth provider is being loaded
        auth_manager_logger.log_message(
            '[SP Auth] ' + _auth_strings[
                'Loading'].get_string(provider=provider))

        # Is the provider loaded?
        if provider in self:

            # If so, send a message that the provider is already loaded
            auth_manager_logger.log_message(
                '[SP Auth] ' + _auth_strings[
                    'Already Loaded'].get_string(provider=provider))

            # No need to go further
            return

        # Does the provider's file exist?
        if not AUTH_PROVIDER_PATH.joinpath(provider + '.py').isfile():

            # Send a message that the file does not exist
            auth_manager_logger.log_message(
                '[SP Auth] ' + _auth_strings[
                    'No Module'].get_string(provider=provider))

            # No need to go further
            return

        # Import the provider's module
        module = import_module('auth.providers.{0}'.format(provider))

        # Loop through all objects in the module
        for module_object in dir(module):

            # Get the object's instance
            instance = getattr(module, module_object)

            # Is the current object a AuthBase instance?
            if isinstance(instance, AuthBase):

                # Found the instance
                break

        # Was no AuthBase instance found?
        else:

            # Raise an error that the object was not found
            raise NotImplementedError(
                'No AuthBase instance found in provider'
                ' "{0}"'.format(provider))

        # Attempt to call the provider's load function
        instance.load()

        # Add the provider to the dictionary
        self[provider] = instance

        # Send a message that the provider was loaded
        auth_manager_logger.log_message(
            '[SP Auth] ' + _auth_strings[
                'Load Successful'].get_string(provider=provider))