# HG changeset patch # User Filip de Waard # Date 1271514214 -7200 # Node ID 030e06d4d79e0d5cd63b33edef59c227489fc509 # Parent 2f37a51682319d2a4038843408fcc3a9272fcbc1 updated to Pylons 1.0rc1 diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 development.ini --- a/development.ini Thu Apr 15 18:57:28 2010 +0200 +++ b/development.ini Sat Apr 17 16:23:34 2010 +0200 @@ -35,6 +35,7 @@ # execute malicious code after an exception is raised. #set debug = false +couchdb_server = http://localhost:5984/ couchdb_uri = http://localhost:5984/vix_dev # Logging configuration diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 setup.py --- a/setup.py Thu Apr 15 18:57:28 2010 +0200 +++ b/setup.py Sat Apr 17 16:23:34 2010 +0200 @@ -14,10 +14,13 @@ url='http://hg.vix.io/vix/', license='Apache License, version 2', install_requires=[ - "Pylons>=0.9.7", + "Pylons>=1.0rc1", "CouchDB", "bcrypt" ], + dependency_links = [ + "http://pylonshq.com/download/1.0rc1" + ], setup_requires=["PasteScript>=1.6.3"], packages=find_packages(exclude=['ez_setup']), include_package_data=True, diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 test.ini --- a/test.ini Thu Apr 15 18:57:28 2010 +0200 +++ b/test.ini Sat Apr 17 16:23:34 2010 +0200 @@ -17,6 +17,5 @@ [app:main] use = config:development.ini -couchdb_server = http://localhost:5984/ # Add additional test specific configuration options as necessary. diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/config/environment.py --- a/vix/config/environment.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/config/environment.py Sat Apr 17 16:23:34 2010 +0200 @@ -1,19 +1,22 @@ """Pylons environment configuration""" import os -from couchdb.client import Database +import couchdb.client + from mako.lookup import TemplateLookup -from pylons import config from pylons.error import handle_mako_error +from pylons.configuration import PylonsConfig import vix.lib.app_globals as app_globals import vix.lib.helpers from vix.config.routing import make_map +import vix.model def load_environment(global_conf, app_conf): - """Configure the Pylons environment via the ``pylons.config`` - object - """ + """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, @@ -24,10 +27,14 @@ # Initialize config with the basic options config.init_app(global_conf, app_conf, package='vix', paths=paths) - config['routes.map'] = make_map() - config['pylons.app_globals'] = app_globals.Globals() + config['routes.map'] = make_map(config) + config['pylons.app_globals'] = app_globals.Globals(config) config['pylons.h'] = vix.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'], @@ -39,5 +46,7 @@ # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) - #setup CouchDB connection configuration - config['vix.db'] = Database(config['couchdb_uri']) + #setup CouchDB connection + config['vix.db'] = couchdb.client.Database(config['couchdb_uri']) + vix.model.server = couchdb.client.Server(config['couchdb_server']) + return config diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/config/middleware.py --- a/vix/config/middleware.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/config/middleware.py Sat Apr 17 16:23:34 2010 +0200 @@ -1,10 +1,9 @@ """Pylons middleware initialization""" -from beaker.middleware import CacheMiddleware, SessionMiddleware +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.middleware import ErrorHandler, StatusCodeRedirect from pylons.wsgiapp import PylonsApp from routes.middleware import RoutesMiddleware @@ -35,15 +34,14 @@ """ # 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 = RoutesMiddleware(app, config['routes.map'], singleton=False) app = SessionMiddleware(app, config) - app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) @@ -66,4 +64,6 @@ static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) + app.config = config + return app diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/config/routing.py --- a/vix/config/routing.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/config/routing.py Sat Apr 17 16:23:34 2010 +0200 @@ -4,10 +4,9 @@ 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']) diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/lib/app_globals.py --- a/vix/lib/app_globals.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/lib/app_globals.py Sat Apr 17 16:23:34 2010 +0200 @@ -1,5 +1,8 @@ """The application's Globals object""" +from beaker.cache import CacheManager +from beaker.util import parse_cache_config_options + class Globals(object): """Globals acts as a container for objects available throughout the @@ -7,9 +10,11 @@ """ - def __init__(self): + 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)) diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/model/__init__.py --- a/vix/model/__init__.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/model/__init__.py Sat Apr 17 16:23:34 2010 +0200 @@ -28,7 +28,7 @@ _password_re = re.compile('\$2a\$[\d]{2}\$[A-z\d./]{53}') _username_re = re.compile('^[.\w]{2,30}$') -server = client.Server(config['couchdb_server']) +server = None db = None class User(schema.Document): diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/tests/__init__.py --- a/vix/tests/__init__.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/tests/__init__.py Sat Apr 17 16:23:34 2010 +0200 @@ -16,7 +16,7 @@ from paste.deploy import loadapp from paste.script.appinstall import SetupCommand -from pylons import config, url +from pylons import url from routes.util import URLGenerator from webtest import TestApp @@ -27,17 +27,15 @@ __all__ = ['environ', 'url', 'TestController', 'DatabasePoweredTestCase'] # Invoke websetup with the current config file -SetupCommand('setup-app').run([config['__file__']]) +SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']]) environ = {} class TestController(TestCase): def __init__(self, *args, **kwargs): - if pylons.test.pylonsapp: - wsgiapp = pylons.test.pylonsapp - else: - wsgiapp = loadapp('config:%s' % config['__file__']) + wsgiapp = pylons.test.pylonsapp + config = wsgiapp.config self.app = TestApp(wsgiapp) url._push_object(URLGenerator(config['routes.map'], environ)) TestCase.__init__(self, *args, **kwargs) diff -r 2f37a51682319d2a4038843408fcc3a9272fcbc1 -r 030e06d4d79e0d5cd63b33edef59c227489fc509 vix/websetup.py --- a/vix/websetup.py Thu Apr 15 18:57:28 2010 +0200 +++ b/vix/websetup.py Sat Apr 17 16:23:34 2010 +0200 @@ -1,10 +1,13 @@ """Setup the vix application""" import logging +import pylons.test + from vix.config.environment import load_environment log = logging.getLogger(__name__) def setup_app(command, conf, vars): """Place any commands to setup vix here""" - load_environment(conf.global_conf, conf.local_conf) + if not pylons.test.pylonsapp: + load_environment(conf.global_conf, conf.local_conf)