Mihail,
I have this working successfully in a TG2.1b2 setup. Here's the imports and
Class def I use for my custom paster command:
from paste.script import command
import os
import ConfigParser
from sqlalchemy import *
from ..model import DBSession
from sqlalchemy import create_engine
from ..model import *
import transaction
class LoadCommand(command.Command):
"""Loader Command"""
max_args = 3
min_args = 1
summary = __doc__.splitlines()[0]
usage = 'Command, load, loads various objects into the database from CSV
formatted files. \n' + __doc__
group_name = ""
parser = command.Command.standard_parser(verbose=True)
def command(self):
ini = 'development.ini'
sect = 'app:main'
option = 'sqlalchemy.url'
# get sqlalchemy.url config in app:mains
curdir = os.getcwd()
conf = ConfigParser.ConfigParser()
conf.read(os.path.join(curdir, ini))
self.name = "load"
try:
self.dburi = conf.get(sect, option, vars={'here':curdir})
except:
print "you should set sqlalchemy.url in development.ini first"
engine = create_engine(self.dburi, echo=True)
init_model(engine)
... do your own stuff here ...
I hope this helps.
On Thu, May 20, 2010 at 9:21 AM, Михаил Лукин
<[email protected]>wrote:
> Thanks, Ryan!
>
> That's what my command looks like now:
>
> def command(self):
> # initialize turbogears environment
> if not self.options.config:
> self.options.config =
> os.path.join(os.path.dirname(mysite.__file__),
> "..", "development.ini")
> config = appconfig("config:" + self.options.config)
> load_environment(config.global_conf, config.local_conf)
> # execute command ...
>
> --
> Best wishes,
> Mihail Lukin
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<turbogears%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en.