Posts Tagged ‘WSGI’

Using Schevo with a Pylons app

Wednesday, December 6th, 2006

Note: This is based on development versions of the SchevoWsgi package.

SchevoWsgi provides an ability to expose one or more databases to a WSGI environment by way of a Paste filter called dbopener.

To use it in Pylons, first edit your development.ini file. Add these two sections below [DEFAULT], where yourapp is the unique name of your application:

[pipeline:main]
pipeline = dbopener yourapp

[filter:dbopener]
use = egg:SchevoWsgi#dbopener
schevo.db.db = %(here)s/dev.db
verbose = true

Change the [app:main] section name to [app:yourapp], to disambiguate it from the pipeline whose name is main.

Now, provided you have a dev.db Schevo database in the same directory as your development.ini file, it will open it when you serve up the development.ini application.

It is useful to expose the open database more easily by referring to self.db in controller code. To enable this, open yourapp/lib/base.py and add this line above the return statement in the BaseController.__call__ method:

self.db = environ['schevo.db.db']

testing schevo+pylons apps

Wednesday, December 6th, 2006

Note: This is based on a development version of the SchevoWsgi package.

I needed a way to get to an in-memory Schevo database that would be created from scratch every time a functional unit test ran in a Pylons application.

So I added a memory:// URI type to SchevoWsgi's dbopener middleware.

To use it in a Pylons application, make sure you already have a development.ini file that is designed to work with Schevo. Then copy it to testing.ini and change the [filter:dbopener] section to use an in-memory database instead:

[filter:dbopener]
use = egg:SchevoWsgi#dbopener
schevo.db.db = memory://yourapp.schema/1
verbose = true

Change the loadapp line in yourapp/tests/__init__.py to read as follows:

loadapp('config:testing.ini', relative_to=conf_dir)

Console logging in a Pylons development.ini file

Wednesday, December 6th, 2006

I like to see Apache-style console logs when I'm developing web apps. The http server provided by Paste in recent times lost its transaction logging code for perormance reasons. That code is now in a separate module and is called the "translogger".

To turn on console logging of http requests to a Pylons app, edit your app's development.ini file and add this section below the [DEFAULT] section, replacing yourapp with a name representing your application:

[pipeline:main]
pipeline = logger yourapp

[filter:logger]
use = egg:Paste#translogger
setup_console_handler = true

Then, change the [app:main] heading to say [app:yourapp] instead; otherwise the app will conflict with the pipeline that is already named "main".