I would submit that if there is not a better way of doing this, there
*should* be.
Most applications have several pieces - *one* (or several) of them are
contained in the web part, which is the part pylons especially
addresses. But then there could be bunches of different
"maintenance"/"admin"/auxillary functions, many of which are
command-line programs (or, even, desktop/gui programs), all using the
same model and other application structures. Examples include database
import/export, integrity checks, database alters, etc.
I am sure it is not possible to create a "standard" which would satisfy
every requirement in all conditions, but we might be able to come up
with a scheme which is both simple and straightforward, and flexible at
the same time.
- David
Christoph Haas 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.
>
> Christoph
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---