Web Images Videos Maps News Shopping Google Mail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
running scripts using pylons models
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
WSobczuk  
View profile   Translate to Translated (View Original)
 More options 29 June 2007, 22:32
From: WSobczuk <WSobc...@gmail.com>
Date: Fri, 29 Jun 2007 14:32:14 -0700
Local: Fri 29 June 2007 22:32
Subject: running scripts using pylons models
Hello,

I just wasted around 5 hours trying to figure out how to run a job
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.

Regards,

from sqlalchemy import *
import leisurenow.models as model
from paste.deploy import appconfig, config, CONFIG
import sys

config_file = sys.argv[1]
package = sys.argv[2]
func = sys.argv[3]

conf = appconfig('config:'+config_file)
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)

pkg = __import__(package, globals(), locals(), [func])
getattr(pkg, func)()


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Contact 42  
View profile   Translate to Translated (View Original)
 More options 30 June 2007, 03:52
From: Contact 42 <contactm...@gmail.com>
Date: Sat, 30 Jun 2007 12:52:30 +1000
Local: Sat 30 June 2007 03:52
Subject: Re: running scripts using pylons models
Maybe I'm just not getting it, but this looks really complicated for
what it's trying to achieve (not the fault of the OP but more so because
of the paste config stuff).

serioiusly, why not just have

appconfig.py
dburi = 'postgres://user:password@localhost/db'

database.py
import appconfig.py
engine = create_engine(appconfig.dburi)
# tables defined here

model.py
import database
#model classes defined here
model.meta.connect(database.engine)

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WSobczuk  
View profile   Translate to Translated (View Original)
 More options 30 June 2007, 10:08
From: WSobczuk <WSobc...@gmail.com>
Date: Sat, 30 Jun 2007 09:08:52 -0000
Local: Sat 30 June 2007 10:08
Subject: Re: running scripts using pylons models
Well, for one thing you didn't do CONFIG.push_process_config(...), so
not everything would work.

For another thing - if you change the pylons DB config then you have
to edit your script and change it there too - so that's evil.

And the third thing is that it took quiet some time to figure this out
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.

Regards,

On 30 Cze, 04:52, Contact 42 <contactm...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Contact 42  
View profile   Translate to Translated (View Original)
 More options 30 June 2007, 11:45
From: Contact 42 <contactm...@gmail.com>
Date: Sat, 30 Jun 2007 20:45:39 +1000
Local: Sat 30 June 2007 11:45
Subject: Re: running scripts using pylons models
WSobczuk wrote:
> Well, for one thing you didn't do CONFIG.push_process_config(...), so
> not everything would work.

I'm not sure what you mean. I'm not using paste config though.
> For another thing - if you change the pylons DB config then you have
> to edit your script and change it there too - so that's evil.

I don't use the pylons db config. My appconfig.py is my config file. I
am not evil...promise.
> And the third thing is that it took quiet some time to figure this out
> 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.

As I said in my earlier post, I am not saying that your script is not
useful for pylons/paste config, but I am questioning the whole pylons
config thing.

It doesn't sit well with me when i have to boot strap the entire web
framework just because I want reuse my models/database code.

Huy


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Tang  
View profile   Translate to Translated (View Original)
 More options 30 June 2007, 18:47
From: "Daniel Tang" <dan.y.t...@gmail.com>
Date: Sat, 30 Jun 2007 13:47:23 -0400
Local: Sat 30 June 2007 18:47
Subject: Re: running scripts using pylons models
On 6/30/07, WSobczuk <WSobc...@gmail.com> wrote:

> Well, for one thing you didn't do CONFIG.push_process_config(...), so
> not everything would work.

> For another thing - if you change the pylons DB config then you have
> to edit your script and change it there too - so that's evil.

> And the third thing is that it took quiet some time to figure this out
> 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.

> Regards,

Actually, I was hoping for something like this a few hours before you
posted it.  Thanks a bunch!

Dan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google