> I've run a lot of tests and I couldn't set os.environ['SOME_KEY'] > ='some value' and have access to it in welcome/model/db.py. If you > can tell me how to do it then I'll test it out.
GAE probably restricts setting it for security reasons. Your work around is good. Web2py should read os.environ and create an internal env that is writable. Robin On Feb 1, 11:35 am, billf <billferr...@blueyonder.co.uk> wrote: > I've run a lot of tests and I couldn't set os.environ['SOME_KEY'] > ='some value' and have access to it in welcome/model/db.py. If you > can tell me how to do it then I'll test it out. > > As I couldn't get it to work, I did the following which I could get to > work. > > In gaehandler.py, I added "env['app_engine']='GAE'" to wsgiapp > (env,res): > > In main.py, I added "environ['app_engine']='WSGI'" to app_with_logging > (environ, responder): > > Then in welcome/model/db.py I could do "if request.env['app_engine'] > =='GAE':" which is all I need for my current work. > > Bill > > On Feb 1, 3:17 pm, Robin B <robi...@gmail.com> wrote: > > > > Shouldn't there be a non-google value set somewhere else > > > (wsgihandler.py?) and what would the value be ('WSGI'?)? > > > When web2py does its detection in main.py, it can do: > > > runtime = os.environ.get('WEB2PY_RUNTIME']','DEFAULT') > > > > Would it be prefereable to be a boolean (IS_GAE=True) and set > > > elsewhere to False? (I suppose this has problem if another application > > > engine comes along). > > > Yeah, it would be handy to be able to be able to check for known > > runtimes: > > request.env.runtime.is_gae? > > > > As there is already an environ key 'SERVER_SOFTWARE' why create > > > another key 'WEB2PY_MODE'? > > > Google is setting SERVER_SOFTWARE in this case: > > > if os.environ.get('SERVER_SOFTWARE','').startswith('Devel'): > > > gaehandler.py code should only set WEB2PY_MODE if it was not > > externally set by the developer > > > this way the developer can test production mode on localhost > > > export WEB2PY_MODE=PRODUCTION > > dev_appserver.py . > > > > Bill > > > > On Feb 1, 12:36 pm, Robin B <robi...@gmail.com> wrote: > > > > > You are right importing 'google' is insufficient for detection, but > > > > detecting GAE side effects is only slightly better. > > > > > All GAE apps start in gaehandler.py. Simply set the environment > > > > variables in side of gaehandler.py, it results in 100% fool proof > > > > detection. > > > > > At the top of gaelhander.py: > > > > > # foolproof detection in 1 line > > > > os.environ['WEB2PY_RUNTIME'] = 'GOOGLE' > > > > # also set the mode > > > > if os.environ.get('SERVER_SOFTWARE','').startswith('Devel'): > > > > os.environ['WEB2PY_MODE'] = 'DEVELOPMENT' > > > > else: > > > > os.environ['WEB2PY_MODE'] = 'PRODUCTION' > > > > > Robin > > > > > On Feb 1, 4:35 am, billf <billferr...@blueyonder.co.uk> wrote: > > > > > > As a short-term solution, I am using the following patch: > > > > > > In compileapp.py, is_gae is set depending on the result of > > > > > imp.get_magic() so in build_environment() in the same module I store > > > > > is_gae in environment['GAE']. Then in db.py I can say > > > > > > if globals()['GAE']: before importing google stuff and using GQLDB() > > > > > > Have I a) re-invented the wheel, b) come up with a good solution, c) > > > > > missed something important? > > > > > > On Feb 1, 9:06 am, billf <billferr...@blueyonder.co.uk> wrote: > > > > > > > I have installed the google appengine but do not want web2py to use > > > > > > the google datastore just because the libs are there but that is > > > > > > what > > > > > > the welcome app does. > > > > > > > I have read some threads related to detecting GAE but they seemed > > > > > > inconclusive. > > > > > > > Is there a way that, in a model (or elsewhere for that matter) I can > > > > > > detect if the app is running on GAE that doesn't depend on the > > > > > > presence of google libs? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" 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 -~----------~----~----~----~------~----~------~--~---