On Fri, Feb 26, 2010 at 11:17:58AM -0800, DD wrote: > Hi, > I am trying to figure out what would be the best way to write batch > (command line) tools in pylons. > > Basically, what I need is a replica of the configuration that my live > site uses, but instead of controllers getting the requests, its a > command line tool. Everything else (globals, caching, database, etc) > should be the same. > > I looked at the command line utilities section in pylons documentation, > but I can't seem to figure out how to everything loaded properly. > loadapp() gives me an instance of the app that can be passed on to a > wsgi server, but that's not what I was looking for. > > Another option will be to just run a paster serve and write a > controller, but that doesn't seem to be the right way to do things :(. > > What's the best approach to do this?
You can add an entry point to add paster commands that will work with
your app loaded. This requires a bit of hackery, but is pretty
simple.
First, I make a directory project/project/commands.
Second, add an entry point in setup.py:
entry_points="""
[paste.app_factory]
main = project.config.middleware:make_app
[paste.app_install]
main = pylons.util:PylonsInstaller
[paste.paster_command]
MyIsh= project.commands.MyIsh:MyIsh
""",
Third, I follow http://pythonpaste.org/script/developer.html to make
a command. It basically has to be kinda like this:
from paste.script.command import Command
from paste.deploy import appconfig
from pylons import config
from project.config.environment import load_environment
class MyIsh(Command):
def command(self):
conf = appconfig('config:%s' % yourconfigfile)
load_engironment(conf.global_conf, conf.local_conf)
'''do your stuff'''
Fourth, I run it like "paster MyIsh" or "paster --plugin=project MyIsh"
Ross
--
Ross Vandegrift
[email protected]
"If the fight gets hot, the songs get hotter. If the going gets tough,
the songs get tougher."
--Woody Guthrie
signature.asc
Description: Digital signature
