I should add that we have tried both separate scripts and paster entry
points and now prefer the latter for anything that's not just a one-
off task.  An interesting example is schema migration - I will review
our code and see whether it would make a good example to publish as a
recipe.

Mike Burrows wrote:
> We do this quite a lot.  We're also beginning to treat our app's JSON
> interface as a scripting interface (in fact that was one motivation
> for adding it).  That allows you do script tasks that involve more
> than one environment, such as migrating objects from one environment
> to another.  My PathTo/DescribedRoutes combo (http://old.nabble.com/
> Announcing-PathTo-and-DescribedRoutes-for-Python-ts27717520r0.html)
> makes the writing of such scripts pleasanter.
>
> Mike
>
> On Feb 26, 11:25 pm, Ross Vandegrift <[email protected]> wrote:
> > 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 followhttp://pythonpaste.org/script/developer.htmlto 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
> > < 1KViewDownload

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to