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

@ -1,2 +1,3 @@
include newpylonsapp/config/deployment.ini_tmpl
recursive-include ddportfolioservice/public * recursive-include ddportfolioservice/public *
recursive-include ddportfolioservice/templates * recursive-include ddportfolioservice/templates *

View file

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

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service middleware configuration # 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. # This file is part of DDPortfolio service.
# #
@ -21,20 +21,18 @@
# <http://www.gnu.org/licenses/>. # <http://www.gnu.org/licenses/>.
# #
"""Pylons middleware initialization""" """Pylons middleware initialization"""
from beaker.middleware import SessionMiddleware
from paste.cascade import Cascade from paste.cascade import Cascade
from paste.registry import RegistryManager from paste.registry import RegistryManager
from paste.urlparser import StaticURLParser from paste.urlparser import StaticURLParser
from paste.deploy.converters import asbool from paste.deploy.converters import asbool
from pylons.middleware import ErrorHandler, StatusCodeRedirect
from pylons import config
from pylons.error import error_template
from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
StaticJavascripts
from pylons.wsgiapp import PylonsApp from pylons.wsgiapp import PylonsApp
from routes.middleware import RoutesMiddleware
from ddportfolioservice.config.environment import load_environment 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 """Create a Pylons WSGI application and return it
``global_conf`` ``global_conf``
@ -42,38 +40,50 @@ def make_app(global_conf, full_stack=True, **app_conf):
the [DEFAULT] section of the Paste ini file. the [DEFAULT] section of the Paste ini file.
``full_stack`` ``full_stack``
Whether or not this application provides a full WSGI stack (by Whether this application provides a full WSGI stack (by default,
default, meaning it handles its own exceptions and errors). meaning it handles its own exceptions and errors). Disable
Disable full_stack when this application is "managed" by full_stack when this application is "managed" by another WSGI
another WSGI middleware. middleware.
``static_files``
Whether this application serves its own static files; disable
when another web server is responsible for serving them.
``app_conf`` ``app_conf``
The application's local configuration. Normally specified in the The application's local configuration. Normally specified in
[app:<name>] section of the Paste ini file (where <name> the [app:<name>] section of the Paste ini file (where <name>
defaults to main). defaults to main).
""" """
# Configure the Pylons environment # Configure the Pylons environment
load_environment(global_conf, app_conf) config = load_environment(global_conf, app_conf)
# The Pylons WSGI app # 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) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
if asbool(full_stack): if asbool(full_stack):
# Handle Python exceptions # Handle Python exceptions
app = ErrorHandler(app, global_conf, error_template=error_template, app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
**config['pylons.errorware'])
# Display error documents for 401, 403, 404 status codes (and # Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled) # 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 # Establish the Registry for this application
app = RegistryManager(app) app = RegistryManager(app)
# Static files if asbool(static_files):
javascripts_app = StaticJavascripts() # Serve static files
static_app = StaticURLParser(config['pylons.paths']['static_files']) static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, javascripts_app, app]) app = Cascade([static_app, app])
app.config = config
return app return app

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service routing configuration # 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. # 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 may take precedent over the more generic routes. For more information
refer to the routes manual at http://routes.groovie.org/docs/ refer to the routes manual at http://routes.groovie.org/docs/
""" """
from pylons import config
from routes import Mapper from routes import Mapper
def make_map(): def make_map(config):
"""Create, configure and return the routes Mapper""" """Create, configure and return the routes Mapper"""
map = Mapper(directory=config['pylons.paths']['controllers'], 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 # The ErrorController route (handles 404/500 error pages); it should
# likely stay at the top, ensuring it can always be resolved # 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 # CUSTOM ROUTES HERE
map.connect('', controller='ddportfolio', action='index') map.connect('/', controller='ddportfolio', action='index')
map.connect('result', controller='ddportfolio', action='urllist') map.connect('/result', controller='ddportfolio', action='urllist')
map.connect('htmlformhelper.js', controller='showformscripts', map.connect('/htmlformhelper.js', controller='showformscripts',
action='index') 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 return map

View file

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

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service application Globals # DDPortfolio service application Globals
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -21,16 +21,21 @@
# <http://www.gnu.org/licenses/>. # <http://www.gnu.org/licenses/>.
# #
"""The application's Globals object""" """The application's Globals object"""
from pylons import config
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
class Globals(object): class Globals(object):
"""Globals acts as a container for objects available throughout the """Globals acts as a container for objects available throughout the
life of the application life of the application
""" """
def __init__(self): def __init__(self, config):
"""One instance of Globals is created during application """One instance of Globals is created during application
initialization and is available during requests via the 'g' initialization and is available during requests via the
variable 'app_globals' variable
""" """
pass self.cache = CacheManager(**parse_cache_config_options(config))

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service base controller # DDPortfolio service base controller
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -22,18 +22,12 @@
# #
"""The base Controller API """The base Controller API
Provides the BaseController class for subclassing, and other objects Provides the BaseController class for subclassing.
utilized by Controllers.
""" """
from pylons import c, cache, config, g, request, response, session from pylons import tmpl_context as c, request
from pylons.controllers import WSGIController from pylons.controllers import WSGIController
from pylons.controllers.util import abort, etag_cache, redirect_to from pylons.i18n import add_fallback
from pylons.decorators import jsonify, validate from pylons.templating import render_mako as render
from pylons.i18n import _, ungettext, N_, add_fallback
from pylons.templating import render
import ddportfolioservice.lib.helpers as h
import ddportfolioservice.model as model
class BaseController(WSGIController): class BaseController(WSGIController):
@ -50,7 +44,3 @@ class BaseController(WSGIController):
pass pass
c.messages = { 'errors': [], 'messages': [] } c.messages = { 'errors': [], 'messages': [] }
return WSGIController.__call__(self, environ, start_response) return WSGIController.__call__(self, environ, start_response)
# Include the '_' function in the public names
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
or __name == '_']

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service webhelpers # DDPortfolio service webhelpers
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -23,11 +23,6 @@
"""Helper functions """Helper functions
Consists of functions to typically be used within templates, but also Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to both as 'h'. available to Controllers. This module is available to templates as 'h'.
""" """
from webhelpers import *
from webhelpers.html.tags import *
from webhelpers.html.builder import escape from webhelpers.html.builder import escape
from webhelpers.text import *
from webhelpers.textile import *
from routes.util import *

View file

@ -12,12 +12,14 @@ error_email_from = paste@localhost
[server:main] [server:main]
use = egg:Paste#http use = egg:Paste#http
host = 0.0.0.0 host = 127.0.0.1
port = 5000 port = 5000
[app:main] [app:main]
use = egg:ddportfolioservice use = egg:ddportfolioservice
full_stack = true full_stack = true
static_files = true
cache_dir = %(here)s/data cache_dir = %(here)s/data
beaker.session.key = ddportfolioservice beaker.session.key = ddportfolioservice
beaker.session.secret = somesecret beaker.session.secret = somesecret
@ -36,7 +38,7 @@ beaker.session.secret = somesecret
# Logging configuration # Logging configuration
[loggers] [loggers]
keys = root, ddportfolioservice keys = root, routes, ddportfolioservice
[handlers] [handlers]
keys = console keys = console
@ -48,6 +50,12 @@ keys = generic
level = INFO level = INFO
handlers = console handlers = console
[logger_routes]
level = INFO
handlers =
qualname = routes.middleware
# "level = DEBUG" logs the route matched and routing variables.
[logger_ddportfolioservice] [logger_ddportfolioservice]
level = DEBUG level = DEBUG
handlers = handlers =
@ -60,5 +68,5 @@ level = NOTSET
formatter = generic formatter = generic
[formatter_generic] [formatter_generic]
format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] [%(threadName)s] %(message)s
datefmt = %H:%M:%S datefmt = %H:%M:%S

View file

@ -12,6 +12,9 @@ source-dir = docs
doc-dir=docs/html doc-dir=docs/html
make-dirs=1 make-dirs=1
[nosetests]
with-pylons = test.ini
# Babel configuration # Babel configuration
[compile_catalog] [compile_catalog]
domain = ddportfolioservice domain = ddportfolioservice

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# DDPortfolio service setup # DDPortfolio service setup
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info> # Copyright © 2009, 2010 Jan Dittberner <jan@dittberner.info>
# #
# This file is part of DDPortfolio service. # This file is part of DDPortfolio service.
# #
@ -29,7 +29,7 @@ except ImportError:
setup( setup(
name='ddportfolioservice', name='ddportfolioservice',
version='0.1', version='0.2',
description='service to create DDPortfolio URLs', description='service to create DDPortfolio URLs',
long_description="""This is a service implementation that long_description="""This is a service implementation that
returns a set of personalized URLs as outlined in returns a set of personalized URLs as outlined in
@ -48,7 +48,7 @@ array of URLs.""",
author_email='jan@dittberner.info', author_email='jan@dittberner.info',
url='http://debian-stuff.dittberner.info/ddportfolioservice', url='http://debian-stuff.dittberner.info/ddportfolioservice',
license='AGPL-3.0+', license='AGPL-3.0+',
install_requires=["Pylons>=0.9.6.2"], install_requires=["Pylons>=0.10rc1"],
packages=find_packages(exclude=['ez_setup']), packages=find_packages(exclude=['ez_setup']),
include_package_data=True, include_package_data=True,
test_suite='nose.collector', test_suite='nose.collector',
@ -57,6 +57,7 @@ array of URLs.""",
('**.py', 'python', None), ('**.py', 'python', None),
('templates/**.mako', 'mako', None), ('templates/**.mako', 'mako', None),
('public/**', 'ignore', None)]}, ('public/**', 'ignore', None)]},
zip_safe=False,
entry_points=""" entry_points="""
[paste.app_factory] [paste.app_factory]
main = ddportfolioservice.config.middleware:make_app main = ddportfolioservice.config.middleware:make_app

View file

@ -12,7 +12,7 @@ error_email_from = paste@localhost
[server:main] [server:main]
use = egg:Paste#http use = egg:Paste#http
host = 0.0.0.0 host = 127.0.0.1
port = 5000 port = 5000
[app:main] [app:main]