make the application start with pylons 0.10

This commit is contained in:
Jan Dittberner 2010-04-16 21:44:13 +02:00
parent 284844168c
commit 794bed92fd
14 changed files with 167 additions and 77 deletions

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
# DDPortfolio service config package
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
# Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
#
# This file is part of DDPortfolio service.
#

View file

@ -0,0 +1,60 @@
#
# ddportfolioservice - Pylons configuration
#
# The %(here)s variable will be replaced with the parent directory of this file
#
[DEFAULT]
debug = true
email_to = you@yourdomain.com
smtp_server = localhost
error_email_from = paste@localhost
[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 5000
[app:main]
use = egg:ddportfolioservice
full_stack = true
static_files = true
cache_dir = %(here)s/data
beaker.session.key = ddportfolioservice
beaker.session.secret = ${app_instance_secret}
app_instance_uuid = ${app_instance_uuid}
# If you'd like to fine-tune the individual locations of the cache data dirs
# for the Cache data, or the Session saves, un-comment the desired settings
# here:
#beaker.cache.data_dir = %(here)s/data/cache
#beaker.session.data_dir = %(here)s/data/sessions
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised.
set debug = false
# Logging configuration
[loggers]
keys = root
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = console
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s] [%(threadName)s] %(message)s

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
# DDPortfolio service environment configuration
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
# Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
#
# This file is part of DDPortfolio service.
#
@ -23,7 +23,9 @@
"""Pylons environment configuration"""
import os
from pylons import config
from mako.lookup import TemplateLookup
from pylons.configuration import PylonsConfig
from pylons.error import handle_mako_error
import ddportfolioservice.lib.app_globals as app_globals
import ddportfolioservice.lib.helpers
@ -33,6 +35,8 @@ def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
object
"""
config = PylonsConfig()
# Pylons paths
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = dict(root=root,
@ -41,15 +45,26 @@ def load_environment(global_conf, app_conf):
templates=[os.path.join(root, 'templates')])
# Initialize config with the basic options
config.init_app(global_conf, app_conf, package='ddportfolioservice',
template_engine='mako', paths=paths)
config.init_app(global_conf, app_conf, package='ddportfolioservice', paths=paths)
config['routes.map'] = make_map()
config['pylons.g'] = app_globals.Globals()
config['routes.map'] = make_map(config)
config['pylons.app_globals'] = app_globals.Globals(config)
config['pylons.h'] = ddportfolioservice.lib.helpers
# Customize templating options via this variable
tmpl_options = config['buffet.template_options']
# 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'])
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
return config

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
# DDPortfolio service middleware configuration
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
# Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
#
# This file is part of DDPortfolio service.
#
@ -21,20 +21,18 @@
# <http://www.gnu.org/licenses/>.
#
"""Pylons middleware initialization"""
from beaker.middleware import SessionMiddleware
from paste.cascade import Cascade
from paste.registry import RegistryManager
from paste.urlparser import StaticURLParser
from paste.deploy.converters import asbool
from pylons import config
from pylons.error import error_template
from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
StaticJavascripts
from pylons.middleware import ErrorHandler, StatusCodeRedirect
from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware
from ddportfolioservice.config.environment import load_environment
def make_app(global_conf, full_stack=True, **app_conf):
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
"""Create a Pylons WSGI application and return it
``global_conf``
@ -42,38 +40,50 @@ def make_app(global_conf, full_stack=True, **app_conf):
the [DEFAULT] section of the Paste ini file.
``full_stack``
Whether or not 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.
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>
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
load_environment(global_conf, app_conf)
config = load_environment(global_conf, app_conf)
# The Pylons WSGI app
app = PylonsApp()
app = PylonsApp(config=config)
# Routing/Session/Cache Middleware
app = RoutesMiddleware(app, config['routes.map'])
app = SessionMiddleware(app, config)
# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
if asbool(full_stack):
# Handle Python exceptions
app = ErrorHandler(app, global_conf, error_template=error_template,
**config['pylons.errorware'])
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
# Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled)
app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
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)
# Static files
javascripts_app = StaticJavascripts()
static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, javascripts_app, 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

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
# DDPortfolio service routing configuration
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
# Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
#
# This file is part of DDPortfolio service.
#
@ -26,24 +26,26 @@ The more specific and detailed routes should be defined first so they
may take precedent over the more generic routes. For more information
refer to the routes manual at http://routes.groovie.org/docs/
"""
from pylons import config
from routes import Mapper
def make_map():
def make_map(config):
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config['pylons.paths']['controllers'],
always_scan=config['debug'])
always_scan=config['debug'], explicit=True)
map.minimization = False
# The ErrorController route (handles 404/500 error pages); it should
# likely stay at the top, ensuring it can always be resolved
map.connect('error/:action/:id', controller='error')
map.connect('/error/{action}', controller='error')
map.connect('/error/{action}/{id}', controller='error')
# CUSTOM ROUTES HERE
map.connect('', controller='ddportfolio', action='index')
map.connect('result', controller='ddportfolio', action='urllist')
map.connect('htmlformhelper.js', controller='showformscripts',
map.connect('/', controller='ddportfolio', action='index')
map.connect('/result', controller='ddportfolio', action='urllist')
map.connect('/htmlformhelper.js', controller='showformscripts',
action='index')
map.connect(':controller/:action/:id')
map.connect('*url', controller='template', action='view')
map.connect('/{controller}/{action}')
map.connect('/{controller}/{action}/{id}')
return map