Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion running scripts using pylons models

View Parsed - Show only message text

Received: by 10.35.107.20 with SMTP id j20mr188684pym.1183152735228;
        Fri, 29 Jun 2007 14:32:15 -0700 (PDT)
Received: by k79g2000hse.googlegroups.com with HTTP;
	Fri, 29 Jun 2007 21:32:14 +0000 (UTC)
X-IP: 212.2.100.133
From:  WSobczuk <WSobc...@gmail.com>
To:  pylons-discuss <pylons-discuss@googlegroups.com>
Subject: running scripts using pylons models
Date: Fri, 29 Jun 2007 14:32:14 -0700
Message-ID: <1183152734.161830.274250@k79g2000hse.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4,gzip(gfe),gzip(gfe)
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-2"

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)()


Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google