| |
pylons-discuss |
Well, for one thing you didn't do CONFIG.push_process_config(...), so For another thing - if you change the pylons DB config then you have And the third thing is that it took quiet some time to figure this out Regards, On 30 Cze, 04:52, Contact 42 <contactm...@gmail.com> wrote: > serioiusly, why not just have > appconfig.py > database.py > model.py > Then if you need to use any of this in a script, it's as simple as importing any of these modules into your script. Just plain python. Nothing special. > Huy > > Hello, > > I just wasted around 5 hours trying to figure out how to run a job > > Regards, > > from sqlalchemy import * > > config_file = sys.argv[1] > > conf = appconfig('config:'+config_file) > > pkg = __import__(package, globals(), locals(), [func])
not everything would work.
to edit your script and change it there too - so that's evil.
for me so I think that if there was a script like this in the project
out of the box - then it could save some people a lot of time and
stress with pylons.
> what it's trying to achieve (not the fault of the OP but more so because
> of the paste config stuff).
> dburi = 'postgres://user:password@localhost/db'
> import appconfig.py
> engine = create_engine(appconfig.dburi)
> # tables defined here
> import database
> #model classes defined here
> model.meta.connect(database.engine)
> > that would use pylons models/config. I finally did it so I'm
> > submitting this script here and hoping that it will be somehow
> > integrated into pylons and the documentation. I hope that as a result
> > it will save other peoples time and make pylons a better experience.
> > import leisurenow.models as model
> > from paste.deploy import appconfig, config, CONFIG
> > import sys
> > package = sys.argv[2]
> > func = sys.argv[3]
> > conf.update(dict(app_conf=conf.local_conf,
> > global_conf=conf.global_conf))
> > CONFIG.push_process_config(conf)
> > if not conf.has_key('sqlalchemy.dburi'):
> > raise KeyError("No sqlalchemy database config found!")
> > print "Connecting to database %s..."%repr(conf['sqlalchemy.dburi'])
> > engine = create_engine(conf['sqlalchemy.dburi'])
> > model.meta.connect(engine)
> > getattr(pkg, func)()