On 3/29/07, Christoph Haas <[EMAIL PROTECTED]> wrote: > Dear list... > > I (still) work on my task to do some database maintainance on the tables > that I use in Pylons as models. So it sounds clever to reuse my > configuration (.ini file) to connect to the database and get access to my > sqlalchemy-mapped classes. The only solution I have so far looks like: > > ------------------------------------------------------------- > import paste.deploy > import pylons.database > import sqlalchemy > import myproject.models as model > > app_conf = paste.deploy.appconfig('config:development.ini', > relative_to='.') > paste.deploy.CONFIG.push_thread_config({'app_conf':app_conf}) > engine = pylons.database.create_engine() > > print model.MyTestModel.get_by(name='John Doe') > ------------------------------------------------------------- > > Can someone please comment on whether this can be done better? I feel dirty > to run paste.deploy.CONFIG.push_thread_config. I'm not even in a thread > context - just want to run a plain Python script. But without it I'm > harrassed by this error: > > TypeError: No configuration has been registered for this process or thread > > How do I properly access my lib/*.py modules and models/__init__.py models > outside of the running Pylons application? I couldn't find anything about > it in the docs. TIA.
This has come up before on the Paste mailing list. I think the answer is to either: * Keep your script stuff completely orthogonal to your Pylons stuff. * Write your script stuff as a Pylons controller that requires special permission (done however you want) and call it as a Web page using either Paste fixture or wget. Sorry, that's the best I have off the top of my head. Best Regards, -jj -- http://jjinux.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---