summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2012-03-06 16:08:33 -0800
committerVishvananda Ishaya <vishvananda@gmail.com>2012-03-06 17:53:17 -0800
commit6ee8a083f01efa183d4611566ef77d3e530df96a (patch)
tree11f928fe57e1a2f775f0cd09466add305d2fc2b6 /tools
parent52d2ba8237d72b98cae63af65fc8ec00fa50bac4 (diff)
downloadnova-6ee8a083f01efa183d4611566ef77d3e530df96a.tar.gz
nova-6ee8a083f01efa183d4611566ef77d3e530df96a.tar.xz
nova-6ee8a083f01efa183d4611566ef77d3e530df96a.zip
Cleans up the create_conf tool
* Makes it adhere to the config file format * Puts the sample output in etc/nova/nova.conf.sample * Updating sample is as easy as ./tools/conf/generate_sample.sh Change-Id: I01e72cb58dd598a74f50c2c17f102d24df325f2e
Diffstat (limited to 'tools')
-rw-r--r--tools/conf/create_conf.py36
-rwxr-xr-xtools/conf/generate_sample.sh (renamed from tools/conf/run.sh)8
2 files changed, 28 insertions, 16 deletions
diff --git a/tools/conf/create_conf.py b/tools/conf/create_conf.py
index af702f732..361c9efef 100644
--- a/tools/conf/create_conf.py
+++ b/tools/conf/create_conf.py
@@ -16,9 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""Generates a nova.conf file.
-
-"""
+"""Generates a nova.conf file."""
import os
import re
@@ -52,9 +50,12 @@ def main(srcfiles):
"console", "consoleauth", "image"]
return prefer.index(pkg_str) if pkg_str in prefer else ord(pkg_str[0])
- print '#', 'nova.conf sample\n'
+ print '#' * 20 + '\n# nova.conf sample #\n' + '#' * 20
# NOTE(lzyeval): sort top level modules and packages
# to process modules first
+ print
+ print '[DEFAULT]'
+ print
mods_by_pkg = dict()
for filepath in srcfiles:
pkg_name = filepath.split(os.sep)[3]
@@ -96,14 +97,14 @@ def print_module(mod_str):
# check if option was processed
if opt_name in _OPTION_CACHE:
continue
- opt_dict = flags.retrieve_opt(opt_name)
+ opt_dict = flags._get_opt_info(opt_name)
opts.append(opt_dict['opt'])
_OPTION_CACHE.append(opt_name)
# return if flags has no unique options
if not opts:
return
# print out module info
- print ''.join(['[', mod_str, ']'])
+ print '######### defined in %s #########' % mod_str
print
for opt in opts:
print_opt(opt)
@@ -118,16 +119,21 @@ def print_opt(opt):
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
# print out option info
- print "#", "".join(["(", opt_type, ")"]), opt.help
- if opt_type == _BOOLOPT:
- print "# default: %s" % opt.default
- print "#", ''.join(["--", opt.name])
+ print "######", "".join(["(", opt_type, ")"]), opt.help
+ if opt.default is None:
+ print '# %s=<None>' % opt.name
else:
- opt_value = str(opt.default)
- if (opt.default is None or (opt_type == _STROPT and not opt.default)):
- opt_value = "<%s>" % opt.name
- print "#", ''.join(["--", opt.name, "=", opt_value])
- print
+ if opt_type == 'StrOpt':
+ print '# %s="%s"' % (opt.name, opt.default)
+ elif opt_type == 'ListOpt':
+ print '# %s="%s"' % (opt.name, ','.join(opt.default))
+ elif opt_type == 'MultiStrOpt':
+ for default in opt.default:
+ print '# %s="%s"' % (opt.name, default)
+ elif opt_type == 'BoolOpt':
+ print '# %s=%s' % (opt.name, str(opt.default).lower())
+ else:
+ print '# %s=%s' % (opt.name, opt.default)
if __name__ == '__main__':
diff --git a/tools/conf/run.sh b/tools/conf/generate_sample.sh
index f03a77f67..8a4f55524 100755
--- a/tools/conf/run.sh
+++ b/tools/conf/generate_sample.sh
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 SINA Corporation
@@ -15,5 +16,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+pushd $(cd $(dirname "$0") && pwd) >/dev/null
-find ../../nova -type f -name "*.py" ! -path "../../nova/tests/*" -exec grep -l "Opt(" {} \; | sort -u | xargs python create_conf.py > nova.conf.sample
+find ../../nova -type f -name "*.py" ! -path "../../nova/tests/*" -exec \
+ grep -l "Opt(" {} \; | sort -u | xargs python create_conf.py > \
+ ../../etc/nova/nova.conf.sample
+
+popd >/dev/null