diff options
| author | Mark McLoughlin <markmc@redhat.com> | 2012-01-27 20:01:39 +0000 |
|---|---|---|
| committer | Mark McLoughlin <markmc@redhat.com> | 2012-01-27 20:05:38 +0000 |
| commit | af365e448b805812e0cec527f97373e8a050d64a (patch) | |
| tree | 8c774b56134cc4dfbeefd1fbe876597f8139aaed /openstack/common/setup.py | |
| parent | 7633bef9382bc6038837d19eb535bfbdcac76f3f (diff) | |
| download | oslo-af365e448b805812e0cec527f97373e8a050d64a.tar.gz oslo-af365e448b805812e0cec527f97373e8a050d64a.tar.xz oslo-af365e448b805812e0cec527f97373e8a050d64a.zip | |
Add the Mapping interface to cfg.ConfigOpts
Implements blueprint cfg-mapping interface
With cfg, option values are accessed via attributes on ConfigOpts
objects e.g.
conf = ConfigOpts()
conf.register_opt(StrOpt('foo'))
conf()
print conf.foo
One use case that isn't easily supported with option values represented
this way is iterating over all the registered options. Standard
interfaces for listing attributes on an object aren't suitable because
they will list more than just the options.
For this use case alone, it's worth having ConfigOpts implement the
mapping interface. That way we can do e.g.
for opt, value in conf.items():
print "Option %s = %s" % (opt, value)
It's interesting to compare argparse's approach to this problem - option
values are attributes on a Namespace object which has no attributes or
methods to pollute the namespace of option names. This is a nice
approach, but would mean that we would be passing around both a
ConfigOpts object and a Namespace object. That's a bit too much overhead,
and the mapping interface provides a usable workaround where there is a
conflict.
Change-Id: Ic113919a20291048f962999229c76884ebdd5ad8
Diffstat (limited to 'openstack/common/setup.py')
0 files changed, 0 insertions, 0 deletions
