I am playing with the pylons framework and I have found something I
don't know how to do it. I would like to write a python script that
can access the models of my app, by I want to execute directly, not
through a controller. For example, I would like to have a crontab
process that perform some peridocal operations on my databse.
I have tried some "Import" combinations, but I have not managed to do
it.
Any hint ?
Thanks
Nacho
You'll need to know where your config ini file is, and load your app
from the script. Your websetup.py script in your project should have
code to do this (in 0.9.6 it does). If it doesn't, you'll need to run
this first before importing your models (again, this works in 0.9.6):
from paste.deploy import appconfig
from pylons import config
from YOURPROJECT.config.environment import load_environment
conf = appconfig('config:' +'/wherever/your/config.ini')
load_environment(conf.global_conf, conf.local_conf)
import YOURPROJECT.model as model
etc.
Cheers,
Ben
----
#!/usr/local/bin/python2.4
from bolsa.websetup import *
setup_config('', '/path_to_your_apps/myapp/development.ini', '', '')
import myapp.model as model
q = model.Session.query(model.MyClass)
# ... do whatever yo want
model.Session.commit()
-----
and don't forget to set your PYTHONPATH env variable to
'/path_to_your_apps/myapp'
Nacho
2007/9/5, neich <nat...@googlemail.com>:
That is exacltly what I have done. And I found the 'setup_config'
function that does what you explained.
> You'll need to know where your config ini file is, and load your app
> from the script. Your websetup.py script in your project should have
> code to do this (in 0.9.6 it does). If it doesn't, you'll need to run
> this first before importing your models (again, this works in 0.9.6):
>
> from paste.deploy import appconfig
> from pylons import config
>
> from YOURPROJECT.config.environment import load_environment
>
> conf = appconfig('config:' +'/wherever/your/config.ini')
> load_environment(conf.global_conf, conf.local_conf)
>
> import YOURPROJECT.model as model
>
> etc.
>
> Cheers,
> Ben
>
> smime.p7s
> 3KDownload