Althought exec_environment exists I think of it more of workaround
than something that should really be used.

If your my_script.py needs to call a certain function that function
(f) belongs to a model, not a controller. If you put in model you do
not need exec_environment and you can just call it. You can still
expose it in a controller (def f(): return f())/

The other issue many be Auth. You should not call from script a
function that requires login because your script probably does not do
logs in.

Massimo

On Aug 28, 2:22 am, Richard <richar...@gmail.com> wrote:
> hello,
>
> I want to create a script that interacts with my web2py app, and which
> I can call with just "python my_script.py"
> Until now I have been using:
>
> > cd /home/web2py && python web2py.py --import_models --no-cron --shell=test 
> > --run=applications/test/modules/my_script.py
>
> I tried with exec_environment() but Auth is giving me trouble, which
> seems to require a real request object.
> This is the error I get:
>
>   File "applications/test/modules/my_script.py", line 2, in <module>
>     test = exec_environment('applications/test/models/db.py')
>   File "/home/web2py/gluon/shell.py", line 63, in exec_environment
>     execfile(pyfile, env)
>   File "applications/test/models/db.py", line 18, in <module>
>     auth = Auth(globals(), db)
>   File "/home/web2py/gluon/tools.py", line 327, in __init__
>     self.settings.login_url = self.url('user', args='login')
>   File "/home/web2py/gluon/tools.py", line 289, in url
>     f=f, args=args, vars=vars)
>   File "/home/web2py/gluon/html.py", line 175, in URL
>     raise SyntaxError, 'not enough information to build the url'
>
> So, is there a way to create dummy Request objects that will satisfy
> Auth?
> Or is there perhaps a better way to create a standalone script?
>
> Richard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to