from pyramid.config import Configurator
from pyramid.i18n import TranslationStringFactory
from sqlalchemy import engine_from_config

from ringo import add_route
from ringo.lib.sql import DBSession
from ringo.model import Base
from ringo.lib.i18n import translators


# DO NOT REMOVE THESE LINES
# BEGIN AUTOGENERATED IMPORTS
# AUTOREPLACEIMPORT
# END AUTOGENERATED IMPORTS

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings)
    # Include basic ringo configuration.
    config.include('ringo')
    config.commit()

    # Now configure the application and optionally overwrite previously
    translators.append(TranslationStringFactory('{{package}}'))
    config.add_translation_dirs('{{package}}:locale/')


    # DO NOT REMOVE THESE LINES
    # BEGIN AUTOGENERATED ROUTES
    # AUTOREPLACEROUTE
    # END AUTOGENERATED ROUTES

    # done configurations.
    config.scan()
    return config.make_wsgi_app()
