Thanks,
I've now got my commands working through paster (eg. paster
dumpaccount --config development.ini), using your example and help
from http://pythonpaste.org/script/developer.html
For those who might want to do the same, I created my script in the
following manner:
from paste.script.command import Command
import sys,os
from paste.deploy import appconfig
from sqlalchemy import engine_from_config
#import transaction
from plusone.model import metadata
class CommandTemplate(Command):
parser = Command.standard_parser()
parser.add_option('--config', action='store', dest='config',
help='Specify config file')
def setupconfig(self):
if not self.options.config:
print "ERROR: no --config file"
sys.exit(1)
cfgpath = os.path.abspath(self.options.config)
cfg = appconfig('config:%s' % cfgpath)
engine = engine_from_config(cfg, 'sqlalchemy.')
metadata.bind=engine
class DumpAccount(CommandTemplate):
min_args = 1
max_args = 1
summary = "Dump an account"
def command(self):
self.setupconfig()
from plusone.controllers.accounts import AccountsController
a=AccountsController()
data=a.account(self.args[0])
print data
...
& I also needed the following in setup.py:
...
setup(
...
entry_points="""
...
[paste.paster_command]
dumpaccount = plusone.commands:DumpAccount
"""
finally I needed to run:
python setup.py egg_info
and now I have the new command, dumpaccount, ready in paster, which
does what I want.
Actually, the critical steps for a truly standalone script may just
be:
(set up my aqlalchemy engine )
from plusone.model import metadata
metadata.bind=engine
but I haven't tried this.
Alex
On Sep 15, 4:38 pm, Michael Pedersen <[email protected]> wrote:
> I don't have full docs, but I do have working sample code (thanks to Jorge
> for helping me out with it!). View it
> here:http://hgweb.icelus.tzo.com/cardlist/file/c203c20588aa/cardlist/comma...
>
> --
> Michael J. Pedersen
> My IM IDs: Jabber/[email protected], ICQ/103345809, AIM/pedermj022171
> Yahoo/pedermj2002, MSN/[email protected]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---