Codelog

foreach(Snippet aSnippet in CodeLog){ aSnippet.GetSolution(); }

Archive for the ‘turbogears’ tag

Sections in Turbogears Config file

with one comment

In turbogears you have three important config files. One is the dev.cfg file used during development, another is prod.cfg used during deploying your code. The last one is app.cfg file which has parameters which are common to both dev and prod.

When you store the parameters in the app.cfg file, it is good to group related parameters together under a section. A new section can be created by enclosing a word with [ and ], eg: [API]

All this is fine till we come to the point of reading back the values from the config file. We faced this same problem and whenever we tried to read it back, it used to give some error about no such variable present.

After looking through the code of the configparser.py for cherrypy, we saw that there was one more additional parameter called path. The path parameter takes in the section name and the variable inside the section is taken in by the parameter key.

So instead of doing a tg.config.get('url'), you would need to do a tg.config.get('url', path='API').

Though this was slightly different than the usual config parser module, it solved the problem of properly categorizing the config file.

Written by cnu

August 1st, 2008 at 12:37 pm

Posted in Python

Tagged with , ,