After some reflection, I suppose I could write a wrapper script that first runs python web2py.py --import_models --shell=<MyController>/default --run="<My Script>" and then starts web2py normally when using web2py standalone.
That is one workaround. On Wednesday, 28 November 2012 11:19:01 UTC-5, Magnitus wrote: > > Hi gents, > > I have been populating my databases with groups (for access control) > manually for a while and then, switched to running a script that does it, > though I still run the script manually in the web2py context. > > Now, I'd like to programmatically implement this in a sensible way (in a > way that runs by itself and doesn't need human intervention at all). > > Obviously, you could just put the logic that does this in a model, but I > don't like the idea of needlessly increasing the size of my models with > this or running the logic to check the existance of and generate groups for > each request. > > Another alternative would be to put the logic in a module that would be > imported (with the idea that it would run on the first import which is done > only once), but then imported modules don't have access to the web2py > objects (notably, my database handle) unless you pass them on as parameters > which you cannot do in a module's global scope when it is first included. > > This leaves me with cron and running it as a cron job at boot time. > However, it isn't working. > > I tried running my script using the web2py context (ie, python web2py.py > --import_models --shell=<MyController>/default --run="<My Script>") and it > ran fine and generated the db entries I wanted. > > Then, I started my web2py execution with cron activated (ie, python > web2py.py -Y). > > I tried the two varations portayed in the example for the crontab > ("@reboot * * * * root *applications/<My App>/cron/Generate_groups.py" and > the shorter "@reboot root *applications/<My App>/cron/Generate_groups.py). > > And yes, my db transactions end with a db.commit(). > > I've been banging my head against this for two hours and while I'm sure > whatever is wrong with this will come to me over time, this is definitely a > case of sooner would be better than later. > > Insights would be appreciated. > --