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.124.20 with SMTP id b20mr649262pyn.1183171953057;
        Fri, 29 Jun 2007 19:52:33 -0700 (PDT)
Return-Path: <contactm...@gmail.com>
Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.179])
        by mx.google.com with ESMTP id v36si1797698wah.2007.06.29.19.52.32;
        Fri, 29 Jun 2007 19:52:33 -0700 (PDT)
Received-SPF: pass (google.com: domain of contactm...@gmail.com designates 64.233.166.179 as permitted sender)
DomainKey-Status: good (test mode)
Received: by py-out-1112.google.com with SMTP id a25so1793251pyi
        for <pylons-discuss@googlegroups.com>; Fri, 29 Jun 2007 19:52:32 -0700 (PDT)
DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed;
        d=gmail.com; s=beta;
        h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding;
        b=BA2BwwDI3pnpp3mfR/gxutG7wQ7Z1zL5glrMhfAoWeRyntSNzA0UjynDD9ZhM1+3y5N/TiWifcV9Z+WKmobs7Zf2vq1LRD2tTxZcj9SR4voDwG6+dyyQpJwnP2BTup2EKyrvSkOUJzjhiAKFjHLU5S6dQsJKaUXJnSSaIsZjo+U=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=beta;
        h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding;
        b=mNqcgHfWXDwA4lK/EoLY8HsCHTVp53Vt+6BGyaHRABV2eU0DKqEj2PZt1THCzE78YyfOtoBBbybvUEghQW+Kw7edL1oomx/N2btYAbfQvKz0lY/I7Gu7XGtvmyRKxcIgC3SZUZ1b11EVdb1V/D0XX1ikjzeV+4uyR53aRAGQ3zI=
Received: by 10.140.251.1 with SMTP id y1mr839340rvh.1183171952184;
        Fri, 29 Jun 2007 19:52:32 -0700 (PDT)
Return-Path: <contactm...@gmail.com>
Received: from ?192.168.1.180? ( [203.171.91.153])
        by mx.google.com with ESMTP id g6sm12600083rvb.2007.06.29.19.52.30
        (version=TLSv1/SSLv3 cipher=RC4-MD5);
        Fri, 29 Jun 2007 19:52:31 -0700 (PDT)
Message-ID: <4685C56E.3000205@gmail.com>
Date: Sat, 30 Jun 2007 12:52:30 +1000
From: Contact 42 <contactm...@gmail.com>
User-Agent: Thunderbird 2.0.0.4 (Windows/20070604)
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
To: pylons-discuss@googlegroups.com
Subject: Re: running scripts using pylons models
References: <1183152734.161830.274...@k79g2000hse.googlegroups.com>
In-Reply-To: <1183152734.161830.274...@k79g2000hse.googlegroups.com>

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