your recommended way of calling controllers from the command line ?

18 views
Skip to first unread message

achipa

unread,
Nov 25, 2008, 5:55:33 AM11/25/08
to web2py Web Framework
The subject says it all. I know a couple of methods (python -R
wrapper, the older -S patch, piping, etc), but was wondering which you
think is the cleanest (and cross platform) as I'd like to integrate it
into my cron patch (so you could specify controllers/functions in your
crontab file, not just executables).

mdipierro

unread,
Nov 25, 2008, 9:26:24 AM11/25/08
to web2py Web Framework
-R is the cleanest way. ;-)

achipa

unread,
Nov 25, 2008, 10:04:28 AM11/25/08
to web2py Web Framework
Maybe it's just the lack of coffee, but... how do you call a function
in the controller via -R without ending up with cruft in the calling
code or the controller itself ?

mdipierro

unread,
Nov 25, 2008, 10:24:55 AM11/25/08
to web2py Web Framework
Sorry, I misunderstood the question.

Answer a)
With -R you can execute a script. You can use exec_environment(...) to
call a function in a controller. It is described in the manual.

Answer b)
If you feel you need to do this perhaps something is wrong. perhaps
the function belongs to a module, not a controller. Or perhaps you are
doing something I never thought of.


Massimo

achipa

unread,
Nov 25, 2008, 10:54:04 AM11/25/08
to web2py Web Framework
a) is clear

b) Benchmarking, notifications, automation, basically anything that is
not an interactive user request coming from a browser. Modules are
cumbersome as you have to import loads of controller style logic and
you end up with one-liner controller functions which just invoke
module functions and a bloated module with all sorts of imports and
calls that web2py controllers do by default. That's what I meant by
referring to cruft. Note that the fact that it's not a browser call
does NOT mean it does not have an output ! In the simplest form, I
want to get rid of wget http://localhost/app/controller/function style
calls in favor of direct calls (wget calls being the dark side, I
know, but so much simpler and quicker than moving controller content
to modules).

mdipierro

unread,
Nov 25, 2008, 11:17:35 AM11/25/08
to web2py Web Framework
Understood. That is what exec_environment is for.

Jonathan Benn

unread,
Nov 26, 2008, 7:55:48 AM11/26/08
to web2py Web Framework
Hi Achipa,
I run into this problem a lot, because on GAE I can only make db calls
to a running server. So for example, if for an automated test suite I
need to modify the database, I can't do this directly from an outside
testing Python script.

My solution is to create test controller actions that modify the db,
and then expose them via XMLRPC. It works like a charm and makes the
functions very easy to execute from any arbitrary Python script.

--Jonathan

Yarko

unread,
Nov 26, 2008, 10:45:02 AM11/26/08
to web...@googlegroups.com
Hi Jonathan -

Could you write this up? Some (me?!) might find it interesting / useful.

Thank you.

Yarko


Hi Achipa,

--Jonathan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "web2py Web Framework" group.
To post to this group, send email to web...@googlegroups.com
To unsubscribe from this group, send email to web2py+unsubscribe@googlegrou

[The entire original message is not included]

Jonathan Benn

unread,
Nov 27, 2008, 7:41:31 AM11/27/08
to web2py Web Framework
Hi Yarko,


On Nov 26, 6:45 pm, Yarko <yark...@gmail.com> wrote:

> Could you write this up?  Some (me?!) might find it interesting / useful.

Sure! Here's an example:


This is your controller, say "test.py"

################################################################################################
def deleteWidgets(containerId):
'''
Deletes all widgets inside the given container
'''
db(db.widget.container_id == containerId).delete()

################################################################################################
def xmlrpcHandler():
'''
Exposes XML-RPC functions for this controller
'''
return response.xmlrpc(request, [deleteWidgets])



First run your web2py server, then from the Python command line, type
in these lines to delete all Widgets in Container 12:

import xmlrpclib
rpc = xmlrpclib.ServerProxy('http://mydomain/myapp/test/
xmlrpcHandler')
rpc.deleteWidgets(12)


If you find that useful, let me know and I'll try writing up an
AlterEgo page

--Jonathan

mdipierro

unread,
Nov 27, 2008, 11:16:42 AM11/27/08
to web2py Web Framework
I am sure you are aware that now anybody can write a simple loop and
remotely wipe out you table.
Reply all
Reply to author
Forward
0 new messages