settings.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import configparser
  2. import json
  3. import os
  4. class DefaultOption(dict):
  5. def __init__(self, config, section, **kv):
  6. self._config = config
  7. self._section = section
  8. dict.__init__(self, **kv)
  9. def items(self):
  10. _items = []
  11. for option in self:
  12. if not self._config.has_option(self._section, option):
  13. _items.append((option, self[option]))
  14. else:
  15. value_in_config = self._config.get(self._section, option)
  16. _items.append((option, value_in_config))
  17. return _items
  18. config = configparser.ConfigParser()
  19. if os.environ.get('APP_ENV', 'development') == 'development':
  20. config.readfp(open('development.ini'))
  21. elif os.environ.get('APP_ENV') == 'production':
  22. config.readfp(open('production.ini'))
  23. elif os.environ.get('APP_ENV') == 'idctest':
  24. config.readfp(open('idctest.ini'))
  25. elif os.environ.get('APP_ENV') == 'sxkj':
  26. config.readfp(open('sxkj.ini'))
  27. elif os.environ.get('APP_ENV') == 'txtest':
  28. config.readfp(open('txtest.ini'))
  29. elif os.environ.get('APP_ENV') == 'txprod':
  30. config.readfp(open('txprod.ini'))
  31. print(f"get config of {os.environ.get('APP_ENV')}")
  32. print(config.get('DATABASE', 'host'))
  33. hadoop_config = config.get('HADOOP_INNER', 'hadoop_config')
  34. print(json.loads(hadoop_config))