Ejemplo n.º 1
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    config = load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp(config=config)

    # Routing/Session Middleware
    app = RoutesMiddleware(app, config['routes.map'], singleton=False)
    app = SessionMiddleware(app, config)

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    app = make_who_with_config(app, global_conf, app_conf['who.config_file'],
                                    app_conf['who.log_file'], app_conf['who.log_level'])

    # start turbomail adapter
    tm_pylons.start_extension()

    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])
    app.config = config
    return app
Ejemplo n.º 2
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='rejuvu', paths=paths)

    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = rejuvu.lib.helpers

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    engine = engine_from_config(config, 'sqlalchemy.')

    init_model(engine)

    # Setup TurboMail
    tm_pylons.start_extension()
Ejemplo n.º 3
0
    def __init__(self, config):
        """One instance of Globals is created during application
        initialization and is available during requests via the
        'app_globals' variable

        """
        self.cache = CacheManager(**parse_cache_config_options(config))
        tm_pylons.config = config
        tm_pylons.start_extension()
Ejemplo n.º 4
0
    def __init__(self, config):
        """One instance of Globals is created during application
        initialization and is available during requests via the
        'app_globals' variable

        """
        self.cache = CacheManager(**parse_cache_config_options(config))
        from turbomail.adapters import tm_pylons
        tm_pylons.start_extension(config)
Ejemplo n.º 5
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))    
    paths = dict(root=root,
                 controllers=[os.path.join(root, 'controllers')],
                 static_files=[os.path.join(root, 'public')],
                 templates=[os.path.join(root, 'templates')])
    
    midgardmvc.lib.componentloader.load_all(global_conf)
    paths = midgardmvc.lib.componentloader.update_paths(paths)
    
    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='midgardmvc', paths=paths)
    
    if global_conf.has_key("mail.on") and asbool(global_conf["mail.on"]):
        from turbomail.adapters import tm_pylons
        tm_pylons.config = config
        tm_pylons.start_extension()
    
    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = midgardmvc.lib.helpers

    # Setup cache object as early as possible
    import pylons
    pylons.cache._push_object(config['pylons.app_globals'].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'],
        filesystem_checks=config['debug'])

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)
    
    return config
Ejemplo n.º 6
0
 def __init__(self):
     """Do nothing, by default."""
     self.services = ''
     if has_turbomail:
         tm_pylons.start_extension()
     self.pool = ThreadPool(8)
Ejemplo n.º 7
0
 def __init__(self):
     from turbomail.adapters import tm_pylons
     tm_pylons.start_extension()
Ejemplo n.º 8
0
 def __init__(self):
     """Do nothing, by default."""
     from turbomail.adapters import tm_pylons
     tm_pylons.start_extension()