paster somecommand
Can anyone recommend some examples on how to do this? Having read the
PasteScript docs I'm still no closer to understanding how it fits together,
some examples would be a real help.
Alternatively, is there a better way to write a command line tool?
(Some use cases that spring to mind: a mail gateway a la Request Tracker's
inbound mail interface, or a cron job that, say, sends out invoices or
invoice reminders once a day.)
The pylons/models/__init__.py example simply sets up sqlobject's
magic module level '__connection__' variable (this can be a string or
a sqlobject ConnectionHub), then imports your models from other
modules. If you followed this example, an external application could
do something similar: setup the '__connection__' var and import the
models.
If you decide to use paster, the pylons custom 'paster controller'
command can be used as an example, which is here:
http://pylonshq.com/project/pylonshq/browser/Pylons/trunk/pylons/
commands.py
Which is the better solution depends on your situation; but I would
lean towards using paster. In the future, you may want/need other
options from your config file for these command line services -- then
your external application has to reinvent the "how do we configure
our application?" wheel.
--
Philip Jenvey
Yeah, I know that. Do you think then that loading, say, production.ini with
a ConfigParser and looking for a either %(package)s.dburi or sqlobject.dburi
is preferable to letting the pastescript infrastructure take care of that?
Specifically, I don't want to reinvent the wheel -- there is already code
that loads the configuration, and my model is already defined, but one
cannot just import the model modules without knowing that the connection
string is.
>If you decide to use paster, the pylons custom 'paster controller'
>command can be used as an example, which is here:
>
>http://pylonshq.com/project/pylonshq/browser/Pylons/trunk/pylons/
>commands.py
>
>Which is the better solution depends on your situation; but I would
>lean towards using paster. In the future, you may want/need other
>options from your config file for these command line services -- then
>your external application has to reinvent the "how do we configure
>our application?" wheel.
Exactly.
How does paster find the commands, then? Forgive me if this question has an
obvious answer :)
Sounds like we're on the same page (a paste script is preferable).
>
>> If you decide to use paster, the pylons custom 'paster controller'
>> command can be used as an example, which is here:
>>
>> http://pylonshq.com/project/pylonshq/browser/Pylons/trunk/pylons/
>> commands.py
>>
>> Which is the better solution depends on your situation; but I would
>> lean towards using paster. In the future, you may want/need other
>> options from your config file for these command line services -- then
>> your external application has to reinvent the "how do we configure
>> our application?" wheel.
>
> Exactly.
>
> How does paster find the commands, then? Forgive me if this
> question has an
> obvious answer :)
>
I forgot to mention: for paste to actually recognize the command,
you'll need to add an egg entry point to your setup.py. That's
covered in the paste docs, and pylons' setup.py has an example.
http://pythonpaste.org/script/developer.html
http://pylonshq.com/project/pylonshq/browser/Pylons/trunk/setup.py#L72
--
Philip Jenvey