A best pratices it create many files to each enviroments ( local , test , 
production ) .. and at moment which load this files make this conditionals..

Then exists each file separated and you make conditionals out enviroment .. 
and driven conditionals ( in model to example )  and load file app.config 
respective.


if request.is_local():
    file = "private/local.ini"
elif request.env.http_host == "some host":
    file = "private/production.ini"

file_to_test = open(file)


Em terça-feira, 6 de setembro de 2016 21:18:51 UTC-3, 黄祥 escreveu:
>
> is it possible to put condition in appconfig?
> e.g.
> private/appconfig.ini
> ; environment
> [environment]
> type = dev
> ;type = test
> ;type = stage
> ;type = prod
>
> ; Environment condition
> [dev_env]
> condition = request.application != 'test0' or request.is_https != False or 
> request.env.http_host != '127.0.0.1:8000' or request.env.server_port != 
> '8000' or request.env.server_name != 'desktop.local' or request.is_local != 
> True or request.folder != '/Users/user0/site/web2py/applications/test0/'
>
> [test_env]
> condition = request.application != 'test0' or request.is_https != False or 
> request.env.http_host != '127.0.0.1:8000'
>
> [stage_env]
> condition = request.application != 'test0' or request.is_https != False or 
> request.env.http_host != '127.0.0.1:8000'
>
> [prod_env]
> condition = request.application != 'test0' or request.env.http_host != '
> server.pythonanywhere.com' or request.env.server_name != '
> server.pythonanywhere.com' or request.is_local != False or request.folder 
> != '/home/server/web2py/applications/test0/'
>
> models/db.py
> from gluon.contrib.appconfig import AppConfig
> config_path = os.path.join(request.folder, 'private')
>
> ## once in production, set reload=False to gain full speed
> myconf = AppConfig('%s/appconfig.ini' % config_path, reload = True)
> myconf_env = myconf.get('environment.type')
>
> """ 
> # work
> # dev
> #if request.application != 'test0' or request.is_https != False or 
> request.env.http_host != '127.0.0.1:8000' or request.env.server_port != 
> '8000' or request.env.server_name != 'desktop.local' or request.is_local != 
> True or request.folder != '/Users/user0/site/web2py/applications/test0/':
> # test
> #if request.application != 'test0' or request.is_https != False or 
> request.env.http_host != '127.0.0.1:8000':
> # prod
> #if request.application != 'test0' or request.env.http_host != '
> server.pythonanywhere.com' or request.env.server_name != '
> server.pythonanywhere.com' or request.is_local != False or request.folder 
> != '/home/server/web2py/applications/test0/':
> raise HTTP(500, "Please contact your IT Support!")
> """
>
> # not work
> #if myconf.get(myconf_env + '_' + 'env.condition'):
> # not work
> if myconf.take(myconf_env + '_' + 'env.condition'):
> raise HTTP(500, "Please contact your IT Support!")
>
> i've tried before but the result is not expected, no error occured. is 
> there any way to achieve it using web2py way?
>
> thanks and best regards,
> stifan
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to