summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2013-05-23 15:47:11 +0200
committerJulien Danjou <julien@danjou.info>2013-05-24 11:28:45 +0200
commita910848af77f3dac4d40247c8cef0aa7828f9001 (patch)
tree760794819c9b70cf3608adf46f2d072759057fe9 /tools
parentbe77d40c897355906172292f44e020131923b284 (diff)
downloadceilometer-a910848af77f3dac4d40247c8cef0aa7828f9001.tar.gz
Fix and update extract_opts group extraction
Same as the one sent to nova: https://review.openstack.org/#/c/30251/ Change-Id: Iba3c31b320ed93deb295a22cd01518e05bfee8ce Signed-off-by: Julien Danjou <julien@danjou.info>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/conf/extract_opts.py59
1 files changed, 20 insertions, 39 deletions
diff --git a/tools/conf/extract_opts.py b/tools/conf/extract_opts.py
index 329fbfeb..1ad162bf 100755
--- a/tools/conf/extract_opts.py
+++ b/tools/conf/extract_opts.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 SINA Corporation
@@ -20,6 +21,7 @@
"""Extracts OpenStack config option info from module(s)."""
+import gettext
import imp
import os
import re
@@ -31,6 +33,7 @@ from oslo.config import cfg
from ceilometer.openstack.common import importutils
+gettext.install('ceilometer', unicode=1)
STROPT = "StrOpt"
BOOLOPT = "BoolOpt"
@@ -59,7 +62,6 @@ WORDWRAP_WIDTH = 60
def main(srcfiles):
- print '\n'.join(['#' * 26, '# ceilometer.conf sample #', '#' * 26, ''])
mods_by_pkg = dict()
for filepath in srcfiles:
pkg_name = filepath.split(os.sep)[1]
@@ -114,49 +116,26 @@ def _import_module(mod_str):
return None
-def _guess_groups(opt, mod_obj):
- groups = []
+def _is_in_group (opt, group):
+ "Check if opt is in group."
+ for key, value in group._opts.items():
+ if value['opt'] == opt:
+ return True
+ return False
+
+def _guess_groups(opt, mod_obj):
# is it in the DEFAULT group?
- if (opt.dest in cfg.CONF and
- not isinstance(cfg.CONF[opt.dest], cfg.CONF.GroupAttr)):
- groups.append('DEFAULT')
+ if _is_in_group(opt, cfg.CONF):
+ return 'DEFAULT'
# what other groups is it in?
for key, value in cfg.CONF.items():
- if not isinstance(value, cfg.CONF.GroupAttr):
- continue
- if opt.dest not in value:
- continue
- groups.append(key)
-
- if len(groups) == 1:
- return groups[0]
-
- group = None
- for g in groups:
- if g in mod_obj.__name__:
- group = g
- break
-
- if group is None and 'DEFAULT' in groups:
- sys.stderr.write("Guessing that " + opt.dest +
- " in " + mod_obj.__name__ +
- " is in DEFAULT group out of " +
- ','.join(groups) + "\n")
- return 'DEFAULT'
-
- if group is None:
- sys.stderr.write("Unable to guess what group " + opt.dest +
- " in " + mod_obj.__name__ +
- " is in out of " + ','.join(groups) + "\n")
- sys.exit(1)
+ if isinstance(value, cfg.CONF.GroupAttr):
+ if _is_in_group(opt, value._group):
+ return value._group.name
- sys.stderr.write("Guessing that " + opt.dest +
- " in " + mod_obj.__name__ +
- " is in the " + group +
- " group out of " + ','.join(groups) + "\n")
- return group
+ raise RuntimeError("Unable to find group for option %s" % opt.name)
def _list_opts(obj):
@@ -185,7 +164,9 @@ def print_group_opts(group, opts_by_module):
global OPTION_COUNT
for mod, opts in opts_by_module:
OPTION_COUNT += len(opts)
- print '######## defined in %s ########' % mod
+ print '#'
+ print '# Options defined in %s' % mod
+ print '#'
print
for opt in opts:
_print_opt(opt)