Table Of Contents

Previous topic

Modules

Next topic

pylons.configuration – Configuration object and defaults setup

pylons.commands – Command line functions

Paster Commands, for use with paster in your project

The following commands are made available via paster utilizing setuptools points discovery. These can be used from the command line when the directory is the Pylons project.

Commands available:

controller
Create a Controller and accompanying functional test
restcontroller
Create a REST Controller and accompanying functional test
shell
Open an interactive shell with the Pylons app loaded

Example usage:

~/sample$ paster controller account
Creating /Users/ben/sample/sample/controllers/account.py
Creating /Users/ben/sample/sample/tests/functional/test_account.py
~/sample$

How it Works

paster is a command line script (from the PasteScript package) that allows the creation of context sensitive commands. paster looks in the current directory for a .egg-info directory, then loads the paster_plugins.txt file.

Using setuptools entry points, paster looks for functions registered with setuptools as paste.paster_command(). These are defined in the entry_points block in each packages setup.py module.

This same system is used when running paster create to determine what templates are available when creating new projects.

Module Contents

class pylons.commands.ControllerCommand(name)

Create a Controller and accompanying functional test

The Controller command will create the standard controller template file and associated functional test to speed creation of controllers.

Example usage:

yourproj% paster controller comments
Creating yourproj/yourproj/controllers/comments.py
Creating yourproj/yourproj/tests/functional/test_comments.py

If you’d like to have controllers underneath a directory, just include the path as the controller name and the necessary directories will be created for you:

yourproj% paster controller admin/trackback
Creating yourproj/controllers/admin
Creating yourproj/yourproj/controllers/admin/trackback.py
Creating yourproj/yourproj/tests/functional/test_admin_trackback.py
class pylons.commands.RestControllerCommand(name)

Create a REST Controller and accompanying functional test

The RestController command will create a REST-based Controller file for use with the resource() REST-based dispatching. This template includes the methods that resource() dispatches to in addition to doc strings for clarification on when the methods will be called.

The first argument should be the singular form of the REST resource. The second argument is the plural form of the word. If its a nested controller, put the directory information in front as shown in the second example below.

Example usage:

yourproj% paster restcontroller comment comments
Creating yourproj/yourproj/controllers/comments.py
Creating yourproj/yourproj/tests/functional/test_comments.py

If you’d like to have controllers underneath a directory, just include the path as the controller name and the necessary directories will be created for you:

yourproj% paster restcontroller admin/tracback admin/trackbacks
Creating yourproj/controllers/admin
Creating yourproj/yourproj/controllers/admin/trackbacks.py
Creating yourproj/yourproj/tests/functional/test_admin_trackbacks.py
class pylons.commands.ShellCommand(name)

Open an interactive shell with the Pylons app loaded

The optional CONFIG_FILE argument specifies the config file to use for the interactive shell. CONFIG_FILE defaults to ‘development.ini’.

This allows you to test your mapper, models, and simulate web requests using paste.fixture.

Example:

$ paster shell my-development.ini