Re: Using the database models in python scripts

2007-04-06 Thread David Geller

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 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
-~--~~~~--~~--~--~---



Re: Using the database models in python scripts

2007-04-02 Thread Shannon -jj Behrens

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
-~--~~~~--~~--~--~---



Using the database models in python scripts

2007-03-29 Thread Christoph Haas

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 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
-~--~~~~--~~--~--~---