1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import configparser
- import json
- import os
- class DefaultOption(dict):
- def __init__(self, config, section, **kv):
- self._config = config
- self._section = section
- dict.__init__(self, **kv)
- def items(self):
- _items = []
- for option in self:
- if not self._config.has_option(self._section, option):
- _items.append((option, self[option]))
- else:
- value_in_config = self._config.get(self._section, option)
- _items.append((option, value_in_config))
- return _items
- config = configparser.ConfigParser()
- if os.environ.get('APP_ENV', 'development') == 'development':
- config.readfp(open('development.ini'))
- elif os.environ.get('APP_ENV') == 'production':
- config.readfp(open('production.ini'))
- elif os.environ.get('APP_ENV') == 'idctest':
- config.readfp(open('idctest.ini'))
- elif os.environ.get('APP_ENV') == 'idcprod':
- config.readfp(open('idcprod.ini'))
- elif os.environ.get('APP_ENV') == 'sxkj':
- config.readfp(open('sxkj.ini'))
- elif os.environ.get('APP_ENV') == 'txtest':
- config.readfp(open('txtest.ini'))
- elif os.environ.get('APP_ENV') == 'txprod':
- config.readfp(open('txprod.ini'))
- print(f"get config of {os.environ.get('APP_ENV')}")
- print(config.get('DATABASE', 'host'))
- hadoop_config = config.get('HADOOP_INNER', 'hadoop_config')
- print(json.loads(hadoop_config))
|