tg-admin shell equivalent of 'python module.py'

6 views
Skip to first unread message

Daniel Fetchinson

unread,
Mar 16, 2008, 3:10:00 AM3/16/08
to turbo...@googlegroups.com
Hi folks, is it possible to execute a module upon the invocation of
tg-admin shell? Something like

python module.py

but with 'tg-admin shell'. I tried

tg-admin shell module.py

but that had no effect, the code in module.py did not get executed.

Cheers,
Daniel

Florent Aide

unread,
Mar 16, 2008, 5:55:44 AM3/16/08
to turbo...@googlegroups.com

$ tg-admin shell

then in the shell

>>> import module
>>> module.main()

Daniel Fetchinson

unread,
Mar 16, 2008, 1:12:03 PM3/16/08
to turbo...@googlegroups.com
> > Hi folks, is it possible to execute a module upon the invocation of
> > tg-admin shell? Something like
> >
> > python module.py
> >
> > but with 'tg-admin shell'. I tried
> >
> > tg-admin shell module.py
> >
> > but that had no effect, the code in module.py did not get executed.
> >
>
> $ tg-admin shell
>
> then in the shell
>
> >>> import module
> >>> module.main()

Yes, I know, although I sometimes ask stupid questions but I'm not
*that* stupid :))

So basically the answer is that it is not possible to feed the module
on the command line? I'm on linux by the way. The reason I need this
is that it would simplify testing my database quite a bit because for
that I don't need a web interface, browser, etc, and I usually just
put a couple of lines of code into a module and want to execute that
from the command line. Without being able to feed the module from the
command line I always have to enter into the tg-admin shell and type
stuff.

Cheers,
Daniel

Diez B. Roggisch

unread,
Mar 16, 2008, 2:30:38 PM3/16/08
to turbo...@googlegroups.com
Daniel Fetchinson schrieb:

I'm doing this the same way, but you get command-history on the shell,
so at least it's only

up-up-return
up-up-return

Not ideal, but ok.

Diez

Daniel Fetchinson

unread,
Mar 16, 2008, 4:45:39 PM3/16/08
to turbo...@googlegroups.com

I see. I haven't tried tg2 yet but if paster has the same issue I'd
like to propose this as a future enhancement.

Cheers,
Daniel

Christopher Arndt

unread,
Mar 16, 2008, 6:06:01 PM3/16/08
to turbo...@googlegroups.com
Daniel Fetchinson schrieb:

>>> Hi folks, is it possible to execute a module upon the invocation of
>>> tg-admin shell? Something like
>
> The reason I need this
> is that it would simplify testing my database quite a bit because for
> that I don't need a web interface, browser, etc, and I usually just
> put a couple of lines of code into a module and want to execute that
> from the command line.

Why don't you use jsut import the database in your modules/scripts with
"a couple of lines of code"?

http://docs.turbogears.org/1.0/ModelOutsideTG#preview

Then you won't need tg-admin. If you want an interactive interpreter
after running the script, use IPython's/Python's -i option.

When you still want to be able to use the scripts as modules, use the
normal technique:

def run_database_stuff(args)
pass

if __name__ == '__main__':
import sys
run_database_stuff(sys.argv[1:])


Chris

Yo'av Moshe

unread,
Mar 16, 2008, 6:20:08 PM3/16/08
to TurboGears
I've found that after installing IPython, i'm able to run 'tg-admin
shell pythonfile.py'.

Yo'av

On Mar 16, 12:10 am, "Daniel Fetchinson" <fetchin...@googlemail.com>
wrote:

Daniel Fetchinson

unread,
Mar 17, 2008, 2:48:35 AM3/17/08
to turbo...@googlegroups.com


Thanks a lot, this exactly answers my question!

Cheers,
Daniel

Daniel Fetchinson

unread,
Mar 17, 2008, 2:52:23 AM3/17/08
to turbo...@googlegroups.com
> I've found that after installing IPython, i'm able to run 'tg-admin
> shell pythonfile.py'.

And the content of pythonfile.py is executed?
Try putting this into pythonfile.py to see for yourself:

if __name__ == '__main__':
print 'Boooo'

Are the outputs from 'python pythonfile.py' and 'tg-admin shell
pythonfile.py' the same?

Cheers,
Daniel
P.S. Chris' answer actually solves my problem, here I'm just wondering
if ipython makes any difference to the behavior of tg-admin shell.

Yo'av Moshe

unread,
Mar 26, 2008, 9:45:48 AM3/26/08
to TurboGears
Yes, the output is the same.

Yo'av.

On Mar 16, 11:52 pm, "Daniel Fetchinson" <fetchin...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages