Ejemplo n.º 1
0
class PasteResourceManager(IResourceManager):

    #: Files with lines greater than this number will not have syntax highlighting.
    #: Set zero for no limit.
    paste_diffviewer_syntax_highlighting_threshold = IntegerConfigField(
        'paste.diffviewer_syntax_highlighting_threshold', default=0)

    models = [PasteEntry]
Ejemplo n.º 2
0
class ICoreResourceManager(IResourceManager):
    """Register core models globally."""

    #: Enable debug mode
    debug = BooleanConfigField('debug', default=False)

    #: Enable testing mode.  Set this to `True` to enable the test mode
    #: of Inyoka.  For example this activates unittest helpers that have
    #: an additional runtime cost which should not be enabled by default.
    #:
    #: This also enables some special logging so that for example our
    #: celery integration does not push forward to celery but executes
    #: tasks directly and adds them to a special container.
    testing = BooleanConfigField('testing', default=False)

    #: The path to the media folder
    media_root = TextConfigField('media_root',
                                 default=_default_media_data_path)

    #: The secret key used for hashing the cookies and other
    #: security salting.
    secret_key = TextConfigField('secret_key', default=u'CHANGEME')

    #: Base domain name
    base_domain_name = TextConfigField('base_domain_name',
                                       default=u'inyoka.local:5000')

    #: Cookie domain name
    cookie_domain_name = TextConfigField('cookie_domain_name',
                                         default=u'.inyoka.local')

    #: Tag uri base, see RFC 4151. May be changed safely. Change this to a real value!
    tag_uri_base = TextConfigField('tag_uri_base',
                                   default=u'tag:inyoka.local,1970:inyoka/')

    #: Cookie name
    cookie_name = TextConfigField('cookie_name', default=u'inyoka-session')

    #: The default timezone for all users
    default_timezone = TextConfigField('default_timezone',
                                       default=u'Europe/Berlin')

    #: The name of the anonymous user
    anonymous_name = TextConfigField('anonymous_name', default=u'anonymous')

    #: Enable or disable CSRF Protection
    enable_csrf_checks = BooleanConfigField('enable_csrf_checks', default=True)

    #: The website title to show in various places
    website_title = TextConfigField('website_title', default=u'Inyoka Portal')

    #: The mail address used for sending mails
    mail_address = TextConfigField('mail_address',
                                   default=u'*****@*****.**')

    #: The duration a permanent session is valid.  Defined in days, defaults to 30
    permanent_session_lifetime = IntegerConfigField(
        'permanent_session_lifetime', default=30)

    #: Path to the directory that includes static files.  Relative to the inyoka
    #: package path.
    static_path = TextConfigField('static_path', default=u'static')

    #: Exclude inyoka.core.tasks per default to fix the celery loader
    deactivated_components.default.append('inyoka.core.tasks')

    #: register core models
    models = [Cache, Confirm, Tag, Storage]
Ejemplo n.º 3
0
def test_list_config_field():
    field = ListConfigField(None, [1,2,3], IntegerConfigField(0, ''))
    eq_(field.get_default(), [1,2,3])
    eq_(field('2:3:4'), [2,3,4])
    eq_(field([99,99]), [99,99])
Ejemplo n.º 4
0
def test_integer_config_field():
    field = IntegerConfigField(None, 20, min_value=10)
    eq_(field.min_value, 10)
    eq_(field.get_default(), 20)
    eq_(field('20'), 20)
    eq_(field(5), 10)
Ejemplo n.º 5
0
from contextlib import contextmanager
from werkzeug.utils import cached_property
import xapian
from xappy import UnprocessedDocument, Field, IndexerConnection,\
    SearchConnection, errors
from inyoka import Interface
from inyoka.core.api import db, ctx
from inyoka.core.config import TextConfigField, IntegerConfigField
from inyoka.core.resource import IResourceManager
from itertools import ifilter

#: The name of the search database
search_index_folder = TextConfigField('search.folder', default=u'search')

#: How many objects should be displayed per page when searching?
search_count = IntegerConfigField('search.count', default=20)

_index_connection = None
_search_connections = WeakKeyDictionary()


@contextmanager
def get_connection(path, indexer=False, callback=None):
    """Get a connection to the database.

    This function reuses already existing connections.
    """
    global _index_connection, _search_connections

    try:
        _connection_attemts = _new = 0
                                      default='sqlite:///celery.db')
celery_imports = ListConfigField('celery.imports',
                                 default=['inyoka.core.tasks'])
celery_task_serializer = TextConfigField('celery.task_serializer',
                                         default='pickle')
celery_send_task_error_emails = BooleanConfigField(
    'celery.send_task_error_emails', default=False)
celery_eager_propagates_exceptions = BooleanConfigField(
    'celery.eager_propagates_exceptions', default=True)
celery_track_started = BooleanConfigField('celery.track_started', default=True)

# broker settings
broker_backend = TextConfigField('broker.backend',
                                 u'sqlakombu.transport.Transport')
broker_host = TextConfigField('broker.host', 'sqlite:///kombu.db')
broker_port = IntegerConfigField('broker.port', 5672)
broker_user = TextConfigField('broker.user', u'inyoka')
broker_password = TextConfigField('broker.password', u'default')
broker_vhost = TextConfigField('broker.vhost', u'inyoka')


class CeleryLoader(BaseLoader):
    """A customized celery configuration loader that implements a bridge
    between :mod:`inyoka.core.config` and the celery configuration system.
    """
    def read_configuration(self):
        """Read the configuration from configuration file and convert values
        to celery processable values."""
        from celery.registry import tasks
        celeryd_vars = list(ctx.cfg.itersection('celeryd'))
        celery_vars = list(ctx.cfg.itersection('celery'))
Ejemplo n.º 7
0
__all__ = ('cache', )

#: The current configured cache object.  This is set on runtime by :func:`set_cache`.
cache = (type('UnconfiguredCache', (NullCache, ), {}))()

#: Set the caching system.  Choose one of ’null’, ’simple’, ’memcached’ or ’filesystem’.
caching_system = TextConfigField('caching.system', default=u'null')

#: Set the path for the filesystem caches
caching_filesystem_cache_path = TextConfigField(
    'caching.filesystem_cache_path', default=u'/tmp/_inyoka_cache')

#: Set the timeout for the caching system
caching_timeout = IntegerConfigField('caching.timeout',
                                     default=300,
                                     min_value=10)

#: Set the memcached servers.  Comma seperated list of memcached servers
caching_memcached_servers = TextConfigField('caching.memcached_servers',
                                            default=u'')


class DatabaseCache(BaseCache):
    """Database cache backend using Inyokas database framework.

    :param default_timeout:  The timeout a key is valid to use.
    :param max_entries:      The maximum number of entries in the cache.
    :param maxcull:          The maximum number of entries to cull per call if
                             cache is full.
    """
Ejemplo n.º 8
0
from inyoka.utils.logger import logger

#: Used to split various formats of email addresses
_mail_split_re = re.compile(r'^(.*?)(?:\s+<(.+)>)?$')

#: outbox used for unittesting
outbox = []

# Configuration values
email_log_only = BooleanConfigField('email.log_only', default=False)
email_system_email = TextConfigField(
    'email.system_email',
    default=u'noreply@%s' % (ctx.cfg['base_domain_name'].split(':')[0]))

email_smtp_host = TextConfigField('email.smtp_host', default=u'localhost')
email_smtp_port = IntegerConfigField('email.smtp_port', default=25)
email_smtp_user = TextConfigField('email.smtp_user', default=u'')
email_smtp_password = TextConfigField('email.smtp_password', default=u'')
email_smtp_use_tls = BooleanConfigField('email.smtp_use_tls', default=False)


def split_email(s):
    """Split a mail address:

    >>> split_email("John Doe")
    ('John Doe', None)
    >>> split_email("John Doe <*****@*****.**>")
    ('John Doe', '*****@*****.**')
    >>> split_email("*****@*****.**")
    (None, '*****@*****.**')
    """
Ejemplo n.º 9
0
#: consult the Inyoka docs.
database_url = TextConfigField('database.url', default=u'sqlite:///dev.db')

#: Set database debug.  If enabled the database will collect the SQL
#: statements and add them to the bottom of the page for easier debugging.
database_debug = BooleanConfigField('database.debug', default=False)

#: Set database echo.  If enabled the database will echo all submitted
#: statements to the default logger.  That defaults to stdout.
database_echo = BooleanConfigField('database.echo', default=False)

#: Set database pool recycle.  If set to non -1, used as number of seconds
#: between connection recycling.  If this timeout is surpassed, the connection
#: will be closed and replaced with a newly opened connection.
database_pool_recycle = IntegerConfigField('database.pool_recycle',
                                           default=-1,
                                           min_value=-1)

#: Set database pool timeout.  The number of seconds to wait before giving
#: up on a returning connection.  This will not be used if the used database
#: is one of SQLite, Access or Informix as those don't support
#: queued connection pools.
database_pool_timeout = IntegerConfigField('database.pool_timeout',
                                           default=30,
                                           min_value=5)


def get_engine(info=None, force_new=False):
    """Creates the engine if it does not exist and returns
    the current engine.