读取配置文件,conf.d样式
conf_d的Python项目详细描述
读取配置文件,conf.d样式
要求
- python 2.6+或python 3.4+
安装
使用pip:
来自github:
pip install git+git://github.com/josegonzalez/conf_d.git#egg=conf_d
来自PYPI:
pip install conf_d==0.1.0
用法
用法:
# in your /etc/derp/conf file [derp] no: sleep til: brooklyn [herp] sleep: 1 wait: 5.0 timeout: seventy # From your fictional derp module from conf_d import Configuration def digitize(config): for key in config: if not config[key].isdigit(): try: config[key] = float(config[key]) except ValueError: pass else: try: config[key] = int(config[key]) except ValueError: pass return config # All defaults must be strings conf = Configuration( name="derp", path="/etc/derp/conf", main_defaults={ "no": "one", "expected": "the spanish inquisition", "cats": "1", }, section_parser=digitize ) what_not_to_do = conf.get(section='derp', key='no', default="jumping") # "sleep" until_when = conf.get(section='derp', key='til') # "brooklyn" cats = conf.get(section='derp', key='cats') # "1" dogs = conf.get(section='derp', key='dogs') # None sleep = conf.get(section='herp', key='sleep') # 1 wait = conf.get(section='herp', key='wait') # 5.0 timeout = conf.get(section='herp', key='timeout') # "seventy" section_exists = conf.has(section='derp') # True section_exists = conf.has(section='derp', key='no') # True raw_data = conf.raw() # { # 'sections': { # 'herp': { # 'sleep': 1, # 'wait': 5.0, # 'timeout': 'seventy' # } # }, # 'derp': { # 'expected': 'the spanish inquisition', # 'til': 'brooklyn', # 'cats': '1', # 'no': 'sleep' # } # }
更改日志
0.1.0(2018-12-12)
专长:添加释放脚本。[何塞·迪亚兹·冈萨雷斯]
添加对Python3(直至Python3.7)的支持[Xavier Hardy]
添加tox.ini文件 添加gitignore
0.0.4(2013-12-13)
将assertdictequals更改为assertequals。[粘土便士]
允许使用自定义配置分析器。[粘土便士]
不要使用configparser.configparser,而是让用户通过 在分析器中。
0.0.3(2013-05-23)
- 允许从主配置中的条目重写confd\u路径。 [何塞·迪亚兹·冈萨雷斯]
0.0.2(2013-04-18)
- 修复不总是创建主节的问题。[何塞·迪亚兹- 冈萨雷斯]
0.0.1(2013-04-14)
- 初始提交。[何塞·迪亚兹·冈萨雷斯]