[web2py] web2py store config/properties best practice

2011-11-13 Thread Bryan M. Barnard
Is there a recommended or best practice in the community for storing 
settings/configs for a web2py app? For example the location of a web service 
the app is dependent and authentication details that would no be specific to 
the end user? Database, pickled object seem like they may be good options but I 
was wondering what is most common or recommended?

Thanks,
Bryan

Re: [web2py] web2py store config/properties best practice

2011-11-13 Thread Bruno Rocha
I was thinking a lot about this, I ended keeping my configurations in a
separate SQLITE database (because I will also run on GAE and it is easy to
change to datastore namespace)

Also I tested other options.

The better is a plan Python *.py file *located in /modules or /models you
can store CONSTANTS or even better a class with instance attributes for
configuration.

The second option for me is *ConfigParser*, it is a Python built in and is
very easy to write/read config .ini and .cfg files.

Another good option (also used by Sublime-text-2 editor) is plain
*JSON*files, you can create configuration.settings file and store
pure json
syntax there, so it will be easy to dumps or loads() it.

If you are planning to run on GAE, I recommend to use database for
configuration, you can use a different namespace for it, and when running
locally can use SQLITE.


Here it is my implementation of config, after long tests.

https://github.com/rochacbruno/Movuca/blob/master/modules/config.py

it rely on the setup datamodel:
https://github.com/rochacbruno/Movuca/blob/master/modules/datamodel/setup.py

and to access the configurations I do.

from config import Config
config = Config()  # it needs to be an instance because you will have
problems using current at the top level or class level.

db = DAL(uri=config.db.uri, migrate_enabled=config.db.migrate_enables,
pool_size=config.db.pool_size)

Also, there are times when I need to store a list of tuples to use in
validators, so I created a method for that

db.table.field.requires = IS_IN_SET(config.get_list('auth',
'privacy_options'))

In the future I will cache the config instance in memcached.

If you app is a bit simpler you should go with plain Python files in
/modules or /models



-- 

Bruno Rocha
[http://rochacbruno.com.br]