要跨模块使用的全局configparser对象
globconf的Python项目详细描述
全局配置
创建全局configparser对象,而不考虑需要它的项目和模块
开始
在使用globconf的项目中:
from globconf import config
# config will attempt to read local config.ini file if present - required options are verified using.
from globconf import verify_required_options
cfg = verify_required_options('Section name', ['list', 'of', 'required', 'options', 'for', 'the', 'section'])
# if config.ini is not found, then defaults can be read from a string, within the module relying on globconf like so:
if 'Section name' not in config.sections():
config.read_string("""
[important section]
host = critical-system.com
user = REST_USER
pwd = REST_PASSWORD
verify_ssl = false
""")
# or
config.read('some_other_config.ini')
在模块中:
from globconf import config, verify_required_options
class module(object):
def __init__(self):
sec = 'service now'
self.cfg = verify_required_options(sec, ['host', 'user', 'pwd'])
if not self.cfg.getboolean('verify_ssl', fallback=True):
import urllib3
urllib3.disable_warnings(InsecureRequestWarning)
只要有人在全局配置中初始化了所需的部分,您的模块就会很高兴。
先决条件
配置分析器
建筑
生成:
sudo python setup.py sdist bdist_wheel
twine upload dist/*
以从系统中获取一些数据或将其用于小演示为例结束
作者
- steffen schumacher-初始工作-steffenschumacher
许可证
这个项目是在麻省理工学院的许可下授权的-详细信息请参见LICENSE.md文件
致谢
- 向任何使用过代码的人提供帽子小费
- 灵感
- 等