Oslo命令行解析
来源:互联网 发布:java 6位短信验证码 编辑:程序博客网 时间:2024/06/07 08:53
转自http://www.muzixing.com/pages/2014/12/19/ryuxue-xi-oslo.html
首先安装python-virtualenv,此python库可以用于创建一个虚拟的,与外界隔离的运行环境,听起来和docker好像有点像。
sudo apt-get install python-virtualenvvirtualenv example-appcd example-appsource bin/activatepip install oslo.configtouch app.pytouch app.conf
然后修改app.conf。添加了两个group:simple和morestuff。simple组中有一个BoolOpt:enable。morestuff组有StrOpt, ListOpt, DictOpt, IntOpt,和FloatOpt。
[simple]enable = True[morestuff]# StrOptmessage = Hello World# ListOptusernames = ['Licheng', 'Muzixing', 'Distance']# DictOptjobtitles = {'Licheng': 'Manager', 'Muzixing': 'CEO', 'Distance': 'Security Guard'}# IntOptpayday = 20# FloatOptpi = 3.14
修改app.py文件。首先定义两个group,再对两个group的option进行定义。最后使用register_group和register_opts函数来完成group和option的注册。
from __future__ import print_functionfrom oslo_config import cfgopt_simple_group = cfg.OptGroup(name='simple', title='A Simple Example')opt_morestuff_group = cfg.OptGroup(name='morestuff', title='A More Complex Example')simple_opts = [ cfg.BoolOpt('enable', default=False, help=('True enables, False disables'))]morestuff_opts = [ cfg.StrOpt('message', default='No data', help=('A message')), cfg.ListOpt('usernames', default=None, help=('A list of usernames')), cfg.DictOpt('jobtitles', default=None, help=('A dictionary of usernames and job titles')), cfg.IntOpt('payday', default=30, help=('Default payday monthly date')), cfg.FloatOpt('pi', default=0.0, help=('The value of Pi'))]CONF = cfg.CONFCONF.register_group(opt_simple_group)CONF.register_opts(simple_opts, opt_simple_group)CONF.register_group(opt_morestuff_group)CONF.register_opts(morestuff_opts, opt_morestuff_group)if __name__ == "__main__": CONF(default_config_files=['app.conf']) print('(simple) enable: {}'.format(CONF.simple.enable)) print('(morestuff) message :{}'.format(CONF.morestuff.message)) print('(morestuff) usernames: {}'.format(CONF.morestuff.usernames)) print('(morestuff) jobtitles: {}'.format(CONF.morestuff.jobtitles)) print('(morestuff) payday: {}'.format(CONF.morestuff.payday)) print('(morestuff) pi: {}'.format(CONF.morestuff.pi))
完成之后,运行app.py文件。可以查看到相关输出。
0 0
- Oslo命令行解析
- openstack oslo.config配置解析模块
- OpenStack配置解析库——oslo.config
- OpenStack配置解析库oslo.config的使用方法
- OpenStack配置解析库oslo.config的使用方法
- OpenStack配置解析库oslo.config的使用方法
- OpenStack配置解析库oslo.config的使用方法
- oslo config
- oslo.config
- oslo openstack
- Openstack的消息队列机制及其部分代码解析(非oslo.message)
- 命令行参数解析(1)
- 命令行参数解析(2)
- 命令行参数解析实例
- linux解析命令行
- 解析命令行参数
- 命令行参数的解析
- ruby命令行解析
- Ajax跨域设置Access-Control-Allow-Origin
- 模板,各个进制间的转换
- 13. Roman to Integer
- POJ 2318 TOYS + 2398 Toy Storage(计算几何叉积)
- 12. Integer to Roman
- Oslo命令行解析
- 【Android】Android动态代理为SurfaceHolder添加Hook
- 程序员累了怎么办?
- 【LeetCode】72. Edit Distance
- java如何提取url里的域名
- 欧拉函数
- 经典软件设计模型 - MVC
- Intellij IDEA win下快捷键
- Redis简介,安装和配置,停止,卸载(图解方式)