Workout With Friends
Stay fit with a little motivation
 All Classes Namespaces Files Functions Variables Properties
__init__.py
Go to the documentation of this file.
1 ##
2 #
3 # Global access to configuration settings.
4 #
5 # In order for it to work, the settings must be set on startup through the
6 # globalize function. After that, settings can be used globally by importing
7 # the settings object directly.
8 #
9 
10 from pyramid.settings import asbool
11 from wowf.lib.utils import Storage, settings_from_prefix
12 
13 
14 BOOLS = ('t', 'f', 'true', 'false', 'on', 'off')
15 
16 
17 def globalize_settings(config):
18  settings.update(config)
19 
20 
21 ##
22 #
23 # Storage container for settings, which attempts to guess the type, e.g.,
24 # number, boolean, etc. and convert accordingly.
25 #
27 
28  def __getitem__(self, key):
29  value = super(Settings, self).__getitem__(key)
30  if value.lower() in BOOLS:
31  return asbool(value)
32  if value.isdigit():
33  return int(value)
34  return value
35 
36  def from_prefix(self, prefix):
37  return settings_from_prefix(self, prefix)
38 
39 
40 settings = Settings()
41