move to Pylons 0.9.7 and related packages
This commit is contained in:
parent
787f6050d4
commit
30b74165c6
28 changed files with 199 additions and 173 deletions
63
pyalchemybiz/config/deployment.ini_tmpl
Normal file
63
pyalchemybiz/config/deployment.ini_tmpl
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#
|
||||
# pyalchemybiz - 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:pyalchemybiz
|
||||
full_stack = true
|
||||
static_files = true
|
||||
|
||||
cache_dir = %(here)s/data
|
||||
beaker.session.key = pyalchemybiz
|
||||
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
|
||||
|
||||
# SQLAlchemy database URL
|
||||
sqlalchemy.url = sqlite:///production.db
|
||||
|
||||
# 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] %(message)s
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
"""Pylons environment configuration"""
|
||||
import os
|
||||
|
||||
from mako.lookup import TemplateLookup
|
||||
from pylons import config
|
||||
from pylons.error import handle_mako_error
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy.exceptions import NoSuchTableError
|
||||
from sqlalchemy.exc import NoSuchTableError
|
||||
from migrate.versioning.api import db_version
|
||||
|
||||
from pyalchemybiz.model import init_model
|
||||
|
|
@ -12,6 +14,7 @@ import pyalchemybiz.lib.app_globals as app_globals
|
|||
import pyalchemybiz.lib.helpers
|
||||
from pyalchemybiz.config.routing import make_map
|
||||
|
||||
from pyalchemybiz.model import init_model
|
||||
|
||||
def load_environment(global_conf, app_conf):
|
||||
"""Configure the Pylons environment via the ``pylons.config``
|
||||
|
|
@ -25,31 +28,36 @@ 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='pyalchemybiz',
|
||||
template_engine='mako', paths=paths)
|
||||
config.init_app(global_conf, app_conf, package='pyalchemybiz', paths=paths)
|
||||
|
||||
config['routes.map'] = make_map()
|
||||
config['pylons.g'] = app_globals.Globals()
|
||||
config['pylons.app_globals'] = app_globals.Globals()
|
||||
config['pylons.h'] = pyalchemybiz.lib.helpers
|
||||
|
||||
# Customize templating options via this variable
|
||||
tmpl_options = config['buffet.template_options']
|
||||
# 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)
|
||||
engine = \
|
||||
engine_from_config(config, 'sqlalchemy.default.')
|
||||
# Setup the SQLAlchemy database engine
|
||||
engine = engine_from_config(config, 'sqlalchemy.')
|
||||
|
||||
try:
|
||||
init_model(engine)
|
||||
except Exception:
|
||||
except NoSuchTableError:
|
||||
# special handling for calls in websetup.py
|
||||
import inspect
|
||||
frame = inspect.currentframe()
|
||||
try:
|
||||
functions = [current[3] for current in \
|
||||
inspect.getouterframes(frame)]
|
||||
if functions[1] != 'setup_config':
|
||||
if functions[1] != 'setup_app':
|
||||
raise
|
||||
finally:
|
||||
del frame
|
||||
|
||||
# CONFIGURATION OPTIONS HERE (note: all config options will override
|
||||
# any Pylons config options)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
"""Pylons middleware initialization"""
|
||||
from beaker.middleware import CacheMiddleware, 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 pyalchemybiz.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``
|
||||
|
|
@ -21,15 +19,20 @@ 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)
|
||||
|
|
@ -37,22 +40,30 @@ def make_app(global_conf, full_stack=True, **app_conf):
|
|||
# The Pylons WSGI app
|
||||
app = PylonsApp()
|
||||
|
||||
# Routing/Session/Cache Middleware
|
||||
app = RoutesMiddleware(app, config['routes.map'])
|
||||
app = SessionMiddleware(app, config)
|
||||
app = CacheMiddleware(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])
|
||||
|
||||
return app
|
||||
|
|
|
|||
|
|
@ -7,19 +7,21 @@ refer to the routes manual at http://routes.groovie.org/docs/
|
|||
from pylons import config
|
||||
from routes import Mapper
|
||||
|
||||
|
||||
def make_map():
|
||||
"""Create, configure and return the routes Mapper"""
|
||||
map = Mapper(directory=config['pylons.paths']['controllers'],
|
||||
always_scan=config['debug'])
|
||||
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='index', action='index')
|
||||
map.connect(':controller/:action/:id')
|
||||
map.connect('*url', controller='template', action='view')
|
||||
|
||||
map.connect('/', controller='index', action='index')
|
||||
map.connect('/{controller}/{action}')
|
||||
map.connect('/{controller}/{action}/{id}')
|
||||
|
||||
return map
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue