On Wed, Jan 21, 2009 at 4:30 PM, Jonathan Vanasco <[email protected]> wrote:
>
> i store a lot of stuff in config, much of which is 'framework' related
> across modules.
>
> the current way i deal with bools is this ( by storing things in
> app_globals during init )
>
>        g.enable_feature_x= False
>        if 'org.opensn.pylons.enable_feature_x' in config:
>            g.opensn_pylons.enable_feature_x = bool(int(config
> ['org.opensn.pylons.enable_feature_x']))
>
> is there a better way ?

I have a custom function in load_environment that chnages the config
var types and aborts if it can't, checks for required vars, and sets
defaults for optional ones.  However, it has since occurred to me that
this would be a good job for a FormEncode schema, although you'd need
some workaround for the dotted variable names, and meaningful error
messages ("variable X in the [app] section of /a/b/c/development.ini
must be numeric").

I do think this should all be done in load_environment rather than ad
hoc whenever the value is used, because not only does that keep
parsing all in one place, but it prevents the application from
crashing in possibly obscure situations.

-- 
Mike Orr <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to