From 6ee8a083f01efa183d4611566ef77d3e530df96a Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 6 Mar 2012 16:08:33 -0800 Subject: 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 --- tools/conf/create_conf.py | 36 +++++++++++++++++++++--------------- tools/conf/generate_sample.sh | 25 +++++++++++++++++++++++++ tools/conf/run.sh | 19 ------------------- 3 files changed, 46 insertions(+), 34 deletions(-) create mode 100755 tools/conf/generate_sample.sh delete mode 100755 tools/conf/run.sh (limited to 'tools') 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=' % 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/generate_sample.sh b/tools/conf/generate_sample.sh new file mode 100755 index 000000000..8a4f55524 --- /dev/null +++ b/tools/conf/generate_sample.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 SINA Corporation +# All Rights Reserved. +# Author: Zhongyue Luo +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 > \ + ../../etc/nova/nova.conf.sample + +popd >/dev/null diff --git a/tools/conf/run.sh b/tools/conf/run.sh deleted file mode 100755 index f03a77f67..000000000 --- a/tools/conf/run.sh +++ /dev/null @@ -1,19 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2012 SINA Corporation -# All Rights Reserved. -# Author: Zhongyue Luo -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -find ../../nova -type f -name "*.py" ! -path "../../nova/tests/*" -exec grep -l "Opt(" {} \; | sort -u | xargs python create_conf.py > nova.conf.sample -- cgit