Update connfig.sample scripts

This commit is contained in:
ubu 2013-09-05 08:14:22 -04:00 committed by Yulia Portnova
parent f367977a0b
commit 59411bf710
2 changed files with 82 additions and 54 deletions

View File

@ -4,20 +4,24 @@
# All Rights Reserved.
# Author: Zhongyue Luo <lzyeval@gmail.com>
#
# 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
# 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
# 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.
# 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.
"""Extracts OpenStack config option info from module(s)."""
from __future__ import print_function
import __builtin__
setattr(__builtin__, '_', lambda x: x)
import os
import re
import socket
@ -45,10 +49,9 @@ PY_EXT = ".py"
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
WORDWRAP_WIDTH = 60
def main(srcfiles):
print '\n'.join(['#' * 20, '# manila.conf sample #', '#' * 20,
'', '[DEFAULT]', ''])
print('\n'.join(['#' * 20, '# manila.conf sample #', '#' * 20,
'', '[DEFAULT]', '']))
_list_opts(cfg.ConfigOpts,
cfg.__name__ + ':' + cfg.ConfigOpts.__name__)
mods_by_pkg = dict()
@ -68,7 +71,7 @@ def main(srcfiles):
mods.sort()
for mod_str in mods:
_print_module(mod_str)
print "# Total option count: %d" % OPTION_COUNT
print("# Total option count: %d" % OPTION_COUNT)
def _print_module(mod_str):
@ -77,12 +80,9 @@ def _print_module(mod_str):
mod_str = mod_str[:mod_str.rfind(".")]
try:
mod_obj = importutils.import_module(mod_str)
except (ValueError, AttributeError), err:
return
except ImportError, ie:
sys.stderr.write("%s\n" % str(ie))
return
except Exception, e:
except Exception as e:
sys.stderr.write("Failed to collect options from module %s: %s\n" % (
mod_str, str(e)))
return
_list_opts(mod_obj, mod_str)
@ -100,13 +100,13 @@ def _list_opts(obj, name):
return
global OPTION_COUNT
OPTION_COUNT += len(opts)
print '#'
print '# Options defined in %s' % name
print '#'
print
print('#')
print('# Options defined in %s' % name)
print('#')
print()
for opt in opts:
_print_opt(opt)
print
print()
def _get_my_ip():
@ -154,35 +154,35 @@ def _print_opt(opt):
opt_type = None
try:
opt_type = OPTION_REGEX.search(str(type(opt))).group(0)
except (ValueError, AttributeError), err:
except (ValueError, AttributeError) as err:
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
opt_help += ' (' + OPT_TYPES[opt_type] + ')'
print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH))
print('#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)))
try:
if opt_default is None:
print '#%s=<None>' % opt_name
print('#%s=<None>' % opt_name)
elif opt_type == STROPT:
assert(isinstance(opt_default, basestring))
print '#%s=%s' % (opt_name, _sanitize_default(opt_default))
print('#%s=%s' % (opt_name, _sanitize_default(opt_default)))
elif opt_type == BOOLOPT:
assert(isinstance(opt_default, bool))
print '#%s=%s' % (opt_name, str(opt_default).lower())
print('#%s=%s' % (opt_name, str(opt_default).lower()))
elif opt_type == INTOPT:
assert(isinstance(opt_default, int) and
not isinstance(opt_default, bool))
print '#%s=%s' % (opt_name, opt_default)
print('#%s=%s' % (opt_name, opt_default))
elif opt_type == FLOATOPT:
assert(isinstance(opt_default, float))
print '#%s=%s' % (opt_name, opt_default)
print('#%s=%s' % (opt_name, opt_default))
elif opt_type == LISTOPT:
assert(isinstance(opt_default, list))
print '#%s=%s' % (opt_name, ','.join(opt_default))
print('#%s=%s' % (opt_name, ','.join(opt_default)))
elif opt_type == MULTISTROPT:
assert(isinstance(opt_default, list))
for default in opt_default:
print '#%s=%s' % (opt_name, default)
print
print('#%s=%s' % (opt_name, default))
print()
except Exception:
sys.stderr.write('Error in option "%s"\n' % opt_name)
sys.exit(1)
@ -190,6 +190,6 @@ def _print_opt(opt):
if __name__ == '__main__':
if len(sys.argv) < 2:
print "usage: python %s [srcfile]...\n" % sys.argv[0]
print("usage: python %s [srcfile]...\n" % sys.argv[0])
sys.exit(0)
main(sys.argv[1:])

View File

@ -1,24 +1,52 @@
#!/usr/bin/env bash
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 SINA Corporation
# All Rights Reserved.
# Author: Zhongyue Luo <lzyeval@gmail.com>
#
# 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.
FILES=$(find cinder -type f -name "*.py" ! -path "cinder/tests/*" -exec \
print_hint() {
echo "Try \`${0##*/} --help' for more information." >&2
}
PARSED_OPTIONS=$(getopt -n "${0##*/}" -o ho: \
--long help,output-dir: -- "$@")
if [ $? != 0 ] ; then print_hint ; exit 1 ; fi
eval set -- "$PARSED_OPTIONS"
while true; do
case "$1" in
-h|--help)
echo "${0##*/} [options]"
echo ""
echo "options:"
echo "-h, --help show brief help"
echo "-o, --output-dir=DIR File output directory"
exit 0
;;
-o|--output-dir)
shift
OUTPUTDIR=`echo $1 | sed -e 's/\/*$//g'`
shift
;;
--)
break
;;
esac
done
OUTPUTDIR=${OUTPUTDIR:-etc/manila}
if ! [ -d $OUTPUTDIR ]
then
echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2
exit 1
fi
OUTPUTFILE=$OUTPUTDIR/manila.conf.sample
FILES=$(find manila -type f -name "*.py" ! -path "manila/tests/*" -exec \
grep -l "Opt(" {} \; | sort -u)
PYTHONPATH=./:${PYTHONPATH} \
python $(dirname "$0")/extract_opts.py ${FILES} > \
etc/cinder/cinder.conf.sample
python $(dirname "$0")/extract_opts_new.py ${FILES} > \
$OUTPUTFILE
# When we use openstack.common.config.generate we won't need this any more
sed -i 's/^#connection=sqlite.*/#connection=sqlite:\/\/\/\/manila\/openstack\/common\/db\/$sqlite_db/' $OUTPUTFILE