Skip to content

Instantly share code, notes, and snippets.

@mengzhuo
Created September 2, 2014 13:47
Show Gist options
  • Save mengzhuo/caa1a2eaad818c2c3606 to your computer and use it in GitHub Desktop.
Save mengzhuo/caa1a2eaad818c2c3606 to your computer and use it in GitHub Desktop.
configure module (reloadable)
#!/usr/bin/env python
# encoding: utf-8
import os
from ConfigParser import SafeConfigParser
PREFIX = 'ZTY'
setting = SafeConfigParser()
setting.read(['/etc/zty-site.conf',
'~/zty-site.conf'])
for k,v in os.environ.iteritems():
if k.startswith(PREFIX):
section, _, option = k.partition('_')
setting.set(section, option, v)
get = setting.get
getboolean = setting.getboolean
getfloat = setting.getfloat
getint = setting.getint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment