settings.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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') == 'idcprod':
  26. config.readfp(open('idcprod.ini'))
  27. elif os.environ.get('APP_ENV') == 'sxkj':
  28. config.readfp(open('sxkj.ini'))
  29. elif os.environ.get('APP_ENV') == 'txtest':
  30. config.readfp(open('txtest.ini'))
  31. elif os.environ.get('APP_ENV') == 'txprod':
  32. config.readfp(open('txprod.ini'))
  33. print(f"get config of {os.environ.get('APP_ENV')}")
  34. print(config.get('DATABASE', 'host'))
  35. hadoop_config = config.get('HADOOP_INNER', 'hadoop_config')
  36. print(json.loads(hadoop_config))