Exemple #1
0
def get_backend(instance_id=None):
    '''Get the cache configuration information.'''
    config = Config(instance_id)
    config.set_schema('cache', {'backend': str, 'hostname': str, 'port': int})
    cache_config = config.get('cache')

    retval = cache_config.get('backend', 'none')
    return retval
Exemple #2
0
def get_db(instance_id=None):
    if not instance_id:
        instance_id = getInstanceId()
    # FIXME: USE LOCKING!
    if instance_id not in databases:
        config = Config(instance_id)
        config.set_schema('database', {'dsn': str})
        dsn = config.get('database')['dsn']

        top = time()
        databases[instance_id] = init_db(dsn)
        bottom = time()
        log.info("Initialised database for instance %s in %.2fs" %
                 (instance_id, (bottom - top)))
    return databases[instance_id]
Exemple #3
0
def get_db(instance_id=None):
    if not instance_id:
        instance_id = getInstanceId()
    # FIXME: USE LOCKING!
    if instance_id not in databases:
        config = Config(instance_id)
        config.set_schema('database', {'dsn': str})
        dsn = config.get('database')['dsn']

        top = time()
        databases[instance_id] = init_db(dsn)
        bottom = time()
        log.info("Initialised database for instance %s in %.2fs" %
                 (instance_id, (bottom - top)))
    return databases[instance_id]
Exemple #4
0
def get_relay_address_prefix_from_config(configSet, configFileName):
    '''Get the prefix used to mark email addresses to relay from the config.

:param str configSet: The name of the configuration set to look up (see
                      :class:`gs.config.Config`)
:param str configFileName: The name of the configuration file that contains
                           the token.
:return: The address prefix for ``configSet`` in ``configFileName``, or 'p-'
         if absent.
:rtype: ``str``
'''
    config = Config(configSet, configFileName)
    config.set_schema('smtp', {'relay-address-prefix': str})
    ws = config.get('smtp', strict=False)
    retval = ws.get('relay-address-prefix', 'p-')
    return retval
def get_relay_address_prefix_from_config(configSet, configFileName):
    '''Get the prefix used to mark email addresses to relay from the config.

:param str configSet: The name of the configuration set to look up (see
                      :class:`gs.config.Config`)
:param str configFileName: The name of the configuration file that contains
                           the token.
:return: The address prefix for ``configSet`` in ``configFileName``, or 'p-'
         if absent.
:rtype: ``str``
'''
    config = Config(configSet, configFileName)
    config.set_schema('smtp', {'relay-address-prefix': str})
    ws = config.get('smtp', strict=False)
    retval = ws.get('relay-address-prefix', 'p-')
    return retval
Exemple #6
0
def get_token_from_config(configSet, configFileName):
    '''Get the authentication token from the config.

:param str configSet: The name of the configuration set to look up (see
                      :class:`gs.config.Config`)
:param str configFileName: The name of the configuration file that contains
                           the token.
:return: The authentication token for ``configSet`` in ``configFileName``
:rtype: ``str``
:raises ValueError: The token was not present in ``configSet``.
'''
    config = Config(configSet, configFileName)
    config.set_schema('webservice', {'token': str})
    ws = config.get('webservice')
    retval = ws['token']
    if not retval:
        m = 'The token was not set.'
        raise ValueError(m)
    return retval
def get_token_from_config(configSet, configFileName):
    '''Get the authentication token from the config.

:param str configSet: The name of the configuration set to look up (see
                      :class:`gs.config.Config`)
:param str configFileName: The name of the configuration file that contains
                           the token.
:return: The authentication token for ``configSet`` in ``configFileName``
:rtype: ``str``
:raises ValueError: The token was not present in ``configSet``.
'''
    config = Config(configSet, configFileName)
    config.set_schema('webservice', {'token': str})
    ws = config.get('webservice')
    retval = ws['token']
    if not retval:
        m = 'The token was not set.'
        raise ValueError(m)
    return retval
Exemple #8
0
def create_emailUtilities(instance_id=None):
    '''Create the utilities to send the email messages

:param str instance_id: The indentifier for the GroupServer instance
:returns: ``None``

The :func:`create_emailUtilities` function loads the ``smtp`` section of the
configuration of the instance specified by ``instance_id``. If no instance
is specified then :func:`gs.config.getInstanceId` is used to determine the
current instance. It then loads the following configuration options:

* ``hostname``
* ``port``
* ``username``
* ``password``
* ``no_tls``
* ``force_tls``
* ``queuepath``
* ``processorthread``
* ``xverp``

If the XVERP option is ``True`` then
:class:`gs.email.mailer.XVERPSMTPMailer` is registered as the utility used
to connect to the SMTP host; otherwise
:class:`zope.sendmail.mailer.SMTPMailer` is used. In either case the mailer
is configured with the options in the config file.'''
    if not instance_id:
        instance_id = getInstanceId()

    config = Config(instance_id)
    config.set_schema('smtp', {'hostname': str, 'port': int,
                               'username': str, 'password': str,
                               'no_tls': bool_, 'force_tls': bool_,
                               'queuepath': str, 'processorthread': bool_,
                               'xverp': bool_})
    smtpconfig = config.get('smtp', strict=False)
    name = ''
    for key in ('hostname', 'port', 'username', 'password', 'no_tls',
                'force_tls'):
        name += '+%s+' % smtpconfig.get(key, None)

    gsm = getGlobalSiteManager()
    if not queryUtility(IMailer, 'gs.mailer.%s' % name):
        if smtpconfig.get('xverp', False):
            Mailer = XVERPSMTPMailer
        else:
            Mailer = SMTPMailer

        gsm.registerUtility(
            Mailer(
                hostname=smtpconfig.get('hostname', None),
                port=smtpconfig.get('port', None),
                username=smtpconfig.get('username', None),
                password=smtpconfig.get('password', None),
                no_tls=smtpconfig.get('no_tls', None),
                force_tls=smtpconfig.get('force_tls', None)),
            IMailer, name='gs.mailer.%s' % name)
    queuePath = smtpconfig.get('queuepath', '/tmp/mailqueue')
    if not queryUtility(IMailDelivery, name='gs.maildelivery'):
        delivery = QueuedMailDelivery(queuePath)
        gsm.registerUtility(delivery, IMailDelivery, name='gs.maildelivery')
        if smtpconfig.get('processorthread', True):
            mailerObject = getUtility(IMailer, 'gs.mailer.%s' % name)
            thread = QueueProcessorThread()
            thread.setMailer(mailerObject)
            thread.setQueuePath(queuePath)
            thread.start()