config.py 633 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from ConfigParser import ConfigParser
  4. from cStringIO import StringIO
  5. def load_configs(column='config', config_ini_path='config.ini'):
  6. _cp = ConfigParser()
  7. fp = open(config_ini_path, 'rb')
  8. content = fp.read()
  9. fp.close()
  10. # 替换bom信息
  11. content = content.replace('\xef\xbb\xbf', '')
  12. fp = StringIO(content)
  13. _cp.readfp(fp)
  14. return _cp.items(column)
  15. configs = dict(load_configs())
  16. class IniConfig(object):
  17. def __getattribute__(self, *args, **kwargs):
  18. val = configs.get(args[0], '').strip()
  19. return val
  20. ini_config = IniConfig()