Пример #1
0
def configure(registry, task_name):
    settings = registry.settings
    if settings.get('%s_debug_signal' % (task_name,), False):
        from assembl.lib import signals
        signals.listen()
    configure_zmq(settings['changes.socket'], False)
    # temporary solution
    configure_model_watcher(registry, task_name)
Пример #2
0
def configure(registry, task_name):
    settings = registry.settings
    if settings.get('%s_debug_signal' % (task_name, ), False):
        from assembl.lib import signals
        signals.listen()
    configure_zmq(settings['changes.socket'], False)
    # temporary solution
    configure_model_watcher(registry, task_name)
Пример #3
0
 def init_from_celery(self):
     # A task is called through celery, so it may not have basic
     # configuration setup. Go through that setup the first time.
     global _settings, SMTP_DOMAIN_DELAYS
     rootdir = getcwd()
     settings_file = join(rootdir, 'local.ini')
     if not exists(settings_file):
         settings_file = join(rootdir, 'production.ini')
     if not exists(settings_file):
         rootdir = dirname(dirname(dirname(realpath(__file__))))
         settings_file = join(rootdir, 'local.ini')
     if not exists(settings_file):
         settings_file = join(rootdir, 'production.ini')
     if not exists(settings_file):
         raise RuntimeError("Missing settings file")
     _settings = settings = get_appsettings(settings_file, 'assembl')
     configure_zmq(settings['changes_socket'], False)
     config = ConfigParser.SafeConfigParser()
     config.read(settings_file)
     registry = getGlobalSiteManager()
     registry.settings = settings
     set_config(settings)
     configure_engine(settings, True)
     configure_indexing()
     if settings.get('%s_debug_signal' % (self.main, ), False):
         from assembl.lib import signals
         signals.listen()
     configure(registry, self.main)
     from .threaded_model_watcher import ThreadDispatcher
     threaded_watcher_class_name = settings.get(
         '%s.threadedmodelwatcher' % (self.main, ),
         "assembl.lib.model_watcher.BaseModelEventWatcher")
     ThreadDispatcher.mw_class = resolver.resolve(
         threaded_watcher_class_name)
     self.mailer = mailer_factory_from_settings(settings)
     # setup SETTINGS_SMTP_DELAY
     for name, val in settings.iteritems():
         if name.startswith(SETTINGS_SMTP_DELAY):
             try:
                 val = timedelta(seconds=float(val))
             except ValueError:
                 print "Not a valid value for %s: %s" % (name, val)
                 continue
             SMTP_DOMAIN_DELAYS[name[len(SETTINGS_SMTP_DELAY):]] = val
     getLogger().info("SMTP_DOMAIN_DELAYS", delays=SMTP_DOMAIN_DELAYS)
     import assembl.tasks.imap
     import assembl.tasks.notify
     import assembl.tasks.notification_dispatch
     import assembl.tasks.translate
     import assembl.tasks.watson
     assembl.tasks.notification_dispatch.create_dispatcher()
Пример #4
0
 def init_from_celery(self):
     # A task is called through celery, so it may not have basic
     # configuration setup. Go through that setup the first time.
     global _settings, SMTP_DOMAIN_DELAYS
     rootdir = getcwd()
     settings_file = join(rootdir, 'local.ini')
     if not exists(settings_file):
         settings_file = join(rootdir, 'production.ini')
     if not exists(settings_file):
         rootdir = dirname(dirname(dirname(realpath(__file__))))
         settings_file = join(rootdir, 'local.ini')
     if not exists(settings_file):
         settings_file = join(rootdir, 'production.ini')
     if not exists(settings_file):
         raise RuntimeError("Missing settings file")
     _settings = settings = get_appsettings(settings_file, 'assembl')
     configure_zmq(settings['changes_socket'], False)
     config = ConfigParser.SafeConfigParser()
     config.read(settings_file)
     registry = getGlobalSiteManager()
     registry.settings = settings
     set_config(settings)
     configure_engine(settings, True)
     configure_indexing()
     if settings.get('%s_debug_signal' % (self.main,), False):
         from assembl.lib import signals
         signals.listen()
     configure(registry, self.main)
     from .threaded_model_watcher import ThreadDispatcher
     threaded_watcher_class_name = settings.get(
         '%s.threadedmodelwatcher' % (self.main,),
         "assembl.lib.model_watcher.BaseModelEventWatcher")
     ThreadDispatcher.mw_class = resolver.resolve(
         threaded_watcher_class_name)
     self.mailer = mailer_factory_from_settings(settings)
     # setup SETTINGS_SMTP_DELAY
     for name, val in settings.iteritems():
         if name.startswith(SETTINGS_SMTP_DELAY):
             try:
                 val = timedelta(seconds=float(val))
             except ValueError:
                 print "Not a valid value for %s: %s" % (name, val)
                 continue
             SMTP_DOMAIN_DELAYS[name[len(SETTINGS_SMTP_DELAY):]] = val
     getLogger().info("SMTP_DOMAIN_DELAYS", delays=SMTP_DOMAIN_DELAYS)
     import assembl.tasks.imap
     import assembl.tasks.notify
     import assembl.tasks.notification_dispatch
     import assembl.tasks.translate
     import assembl.tasks.watson
     assembl.tasks.notification_dispatch.create_dispatcher()
Пример #5
0
def configure(registry, task_name):
    global _settings
    settings = registry.settings
    if _settings is None:
        _settings = settings
    if settings.get('%s_debug_signal' % (task_name, ), False):
        from assembl.lib import signals
        signals.listen()
    configure_zmq(settings['changes.socket'], False)
    # temporary solution
    configure_model_watcher(registry, task_name)
    # configure them all...
    from .notify import notify_celery_app
    config_celery_app(notify_celery_app, settings)
    from .notification_dispatch import notif_dispatch_celery_app
    config_celery_app(notif_dispatch_celery_app, settings)
    from .translate import translation_celery_app
    config_celery_app(translation_celery_app, settings)
    from .imap import imap_celery_app
    config_celery_app(imap_celery_app, settings)
Пример #6
0
def configure(registry, task_name):
    global _settings
    settings = registry.settings
    if _settings is None:
        _settings = settings
    if settings.get('%s_debug_signal' % (task_name,), False):
        from assembl.lib import signals
        signals.listen()
    configure_zmq(settings['changes.socket'], False)
    # temporary solution
    configure_model_watcher(registry, task_name)
    # configure them all...
    from .notify import notify_celery_app
    config_celery_app(notify_celery_app, settings)
    from .notification_dispatch import notif_dispatch_celery_app
    config_celery_app(notif_dispatch_celery_app, settings)
    from .translate import translation_celery_app
    config_celery_app(translation_celery_app, settings)
    from .imap import imap_celery_app
    config_celery_app(imap_celery_app, settings)
Пример #7
0
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    set_config(settings)
    if not session_maker_is_initialized():
        configure_engine(settings)
    if settings.get('assembl_debug_signal', False):
        from assembl.lib import signals
        signals.listen()

    from views.traversal import root_factory
    config = Configurator(registry=getGlobalSiteManager())
    config.setup_registry(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')

    def my_locale_negotiator(request):
        locale = to_posix_format(default_locale_negotiator(request))
        available = settings['available_languages'].split()
        if locale and locale not in available:
            locale_with_country = ensure_locale_has_country(locale)
            if locale_with_country:
                locale = locale_with_country
        if not locale:
            locale = to_posix_format(request.accept_language.best_match(
                available, settings.get('pyramid.default_locale_name', 'en')))
        request._LOCALE_ = locale
        return locale

    config.set_locale_negotiator(my_locale_negotiator)
    config.add_tween(
        'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
        under="pyramid_tm.tm_tween_factory")

    # Tasks first, because it includes ZCA registration (for now)
    config.include('.tasks')

    config.include('pyramid_dogpile_cache')
    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from auth.util import authentication_callback
        auth_policy = SessionAuthenticationPolicy(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    from models import get_session_maker
    from .models.auth import (
        populate_default_roles, populate_default_permissions)
    with transaction.manager:
        session = get_session_maker()
        populate_default_roles(session)
        populate_default_permissions(session)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('widget', 'widget', cache_max_age=3600)
    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.views')

    # config.scan('.lib')
    config.scan('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    config.include('pyramid_mailer')

    config.include('.view_def')

    wsgi_app = config.make_wsgi_app()
    if asbool(settings.get('sqltap', False)):
        wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
    return wsgi_app
Пример #8
0
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    set_config(settings)
    if not session_maker_is_initialized():
        configure_engine(settings)
    if settings.get('assembl_debug_signal', False):
        from assembl.lib import signals
        signals.listen()

    from views.traversal import root_factory
    config = Configurator(registry=getGlobalSiteManager())
    config.setup_registry(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')

    config.set_locale_negotiator(my_locale_negotiator)
    if using_virtuoso():
        config.add_tween(
            'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
            under="pyramid_tm.tm_tween_factory")

    config.include('.auth')
    config.include('.models')
    # Tasks first, because it includes ZCA registration (for now)
    config.include('.tasks')

    config.include('pyramid_dogpile_cache')
    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from auth.util import authentication_callback
        auth_policy_name = settings.get(
            "auth_policy_class", "assembl.auth.util.UpgradingSessionAuthenticationPolicy")
        auth_policy = resolver.resolve(auth_policy_name)(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    from models import get_session_maker
    with transaction.manager:
        session = get_session_maker()
        from .lib.migration import bootstrap_db_data
        bootstrap_db_data(session, False)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('static2', 'static2', cache_max_age=3600)
    config.include('.graphql')  # This MUST be above views import

    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.lib')
    config.include('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    config.include('pyramid_mailer')

    config.include('.view_def')

    wsgi_app = config.make_wsgi_app()
    if asbool(settings.get('sqltap', False)):
        wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
    return wsgi_app
Пример #9
0
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings = dict(global_config, **settings)
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    settings = set_config(settings)
    if not session_maker_is_initialized():
        configure_engine(settings)
    if settings.get('idealoom_debug_signal', False):
        from assembl.lib import signals
        signals.listen()

    import os
    if 'UWSGI_ORIGINAL_PROC_NAME' in os.environ:
        # uwsgi does not load logging properly
        from pyramid.paster import setup_logging
        setup_logging(global_config['__file__'])

    config = Configurator(registry=getGlobalSiteManager())
    config.include('.lib.logging')
    from .views.traversal import root_factory
    config.setup_registry(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')

    config.set_locale_negotiator(my_locale_negotiator)
    config.add_tween('assembl.tweens.logging.logging_tween_factory',
                     over="pyramid_tm.tm_tween_factory")

    config.include('pyramid_retry')
    config.include('.auth')
    config.include('.models')
    bake_lazy_loaders()
    # Tasks first, because it includes ZCA registration (for now)
    config.include('.tasks')

    config.include('pyramid_dogpile_cache')
    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from .auth.util import authentication_callback
        auth_policy_name = settings.get(
            "auth_policy_class",
            "assembl.auth.util.UpgradingSessionAuthenticationPolicy")
        auth_policy = resolver.resolve(auth_policy_name)(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    if not settings.get('in_migration', False):
        from .lib.migration import bootstrap_db, bootstrap_db_data
        db = bootstrap_db(settings['config_uri'])
        bootstrap_db_data(db, settings['config_uri'] != "testing.ini")

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('widget', 'widget', cache_max_age=3600)
    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.lib')
    config.include('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    if 'pyramid_mailer.debug' not in settings.get('pyramid.includes', ()):
        config.include('pyramid_mailer')

    config.include('.view_def')

    wsgi_app = config.make_wsgi_app()
    if asbool(settings.get('sqltap', False)):
        import sqltap.wsgi
        wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
    return wsgi_app
Пример #10
0
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    settings = set_config(settings)
    if not session_maker_is_initialized():
        configure_engine(settings)
    if settings.get('assembl_debug_signal', False):
        from assembl.lib import signals
        signals.listen()

    import os
    if 'UWSGI_ORIGINAL_PROC_NAME' in os.environ:
        # uwsgi does not load logging properly
        from pyramid.paster import setup_logging
        setup_logging(global_config['__file__'])

    # Sentry
    import sentry_sdk
    from sentry_sdk.integrations.pyramid import PyramidIntegration
    if settings.get('sentry_dsn', ''):
        sentry_sdk.init(
            dsn=settings['sentry_dsn'],
            integrations=[PyramidIntegration()]
        )

    from views.traversal import root_factory
    config = Configurator(registry=getGlobalSiteManager())
    config.setup_registry(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')

    config.set_locale_negotiator(my_locale_negotiator)
    config.add_tween(
        'assembl.tweens.logging.logging_tween_factory',
        over="pyramid_tm.tm_tween_factory")

    config.include('.auth')
    config.include('.models')
    config.include('.indexing')
    config.include('.lib.logging')
    # Tasks first, because it includes ZCA registration (for now)
    config.include('.tasks')

    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from auth.util import authentication_callback
        auth_policy_name = settings.get(
            "auth_policy_class", "assembl.auth.util.UpgradingSessionAuthenticationPolicy")
        auth_policy = resolver.resolve(auth_policy_name)(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    from models import get_session_maker
    if not settings.get('in_migration', False):
        with transaction.manager:
            session = get_session_maker()
            from .lib.migration import bootstrap_db_data
            bootstrap_db_data(session, settings['config_uri'] != "testing.ini")

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('static2', 'static2', cache_max_age=3600)
    config.include('.graphql')  # This MUST be above views import

    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.lib')
    config.include('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    config.include('pyramid_mailer')

    config.include('.view_def')

    wsgi_app = config.make_wsgi_app()
    if asbool(settings.get('sqltap', False)):
        import sqltap.wsgi
        wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
    return wsgi_app
Пример #11
0
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    set_config(settings)
    if not session_maker_is_initialized():
        configure_engine(settings)
    if settings.get('assembl_debug_signal', False):
        from assembl.lib import signals
        signals.listen()

    from views.traversal import root_factory
    config = Configurator(registry=getGlobalSiteManager())
    config.setup_registry(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')

    def my_locale_negotiator(request):
        locale = to_posix_format(default_locale_negotiator(request))
        available = settings['available_languages'].split()
        if locale and locale not in available:
            locale_with_country = ensure_locale_has_country(locale)
            if locale_with_country:
                locale = locale_with_country
        if not locale:
            locale = to_posix_format(
                request.accept_language.best_match(
                    available, settings.get('pyramid.default_locale_name',
                                            'en')))
        request._LOCALE_ = locale
        return locale

    config.set_locale_negotiator(my_locale_negotiator)
    config.add_tween(
        'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
        under="pyramid_tm.tm_tween_factory")

    # Tasks first, because it includes ZCA registration (for now)
    config.include('.tasks')

    config.include('pyramid_dogpile_cache')
    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from auth.util import authentication_callback
        auth_policy = SessionAuthenticationPolicy(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    from models import get_session_maker
    from .models.auth import (populate_default_roles,
                              populate_default_permissions)
    with transaction.manager:
        session = get_session_maker()
        populate_default_roles(session)
        populate_default_permissions(session)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('widget', 'widget', cache_max_age=3600)
    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.views')

    # config.scan('.lib')
    config.scan('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    config.include('pyramid_mailer')

    config.include('.view_def')

    wsgi_app = config.make_wsgi_app()
    if asbool(settings.get('sqltap', False)):
        wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
    return wsgi_app
Пример #12
0
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    set_config(settings)
    if not session_maker_is_initialized():
        configure_engine(settings)
    if settings.get('assembl_debug_signal', False):
        from assembl.lib import signals
        signals.listen()

    from views.traversal import root_factory
    config = Configurator(registry=getGlobalSiteManager())
    config.setup_registry(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')

    global locale_negotiator
    locale_negotiator = my_locale_negotiator
    config.set_locale_negotiator(my_locale_negotiator)
    if using_virtuoso():
        config.add_tween(
            'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
            under="pyramid_tm.tm_tween_factory")

    config.include('.models')
    # Tasks first, because it includes ZCA registration (for now)
    config.include('.tasks')

    config.include('pyramid_dogpile_cache')
    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from auth.util import (
            authentication_callback, UpgradingSessionAuthenticationPolicy)
        auth_policy = UpgradingSessionAuthenticationPolicy(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    from models import get_session_maker
    with transaction.manager:
        session = get_session_maker()
        from .lib.migration import bootstrap_db_data
        bootstrap_db_data(session, False)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('widget', 'widget', cache_max_age=3600)
    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.views')

    # config.scan('.lib')
    config.scan('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    config.include('pyramid_mailer')

    config.include('.view_def')

    wsgi_app = config.make_wsgi_app()
    if asbool(settings.get('sqltap', False)):
        wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
    return wsgi_app