From a94232f79df0dbb2606300a7e07b6f965ceff68c Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Fri, 30 Aug 2013 10:34:59 +0800 Subject: [PATCH] Update sample config generator script This patch reverts 13d80020. The help message should be added in oslo-incubator since generate_sample.sh is synced from there also. Resolves bug #1204204 9f2b93b Sample config file generator clean up 33f9f78 Replaces relative path to absolute path in conf file generator c97e17b Refactors if statement in config generator 8b11fda Provide useful defaults for config generator 4c02e0a Unset OS_xx variable before generate configuration Change-Id: I96fcb39c0c620c147fea5c96416e506a758619ce --- nova/openstack/common/config/generator.py | 2 ++ tools/config/generate_sample.sh | 32 ++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/nova/openstack/common/config/generator.py b/nova/openstack/common/config/generator.py index ddc477376aaa..0fc8d72932b9 100644 --- a/nova/openstack/common/config/generator.py +++ b/nova/openstack/common/config/generator.py @@ -29,8 +29,10 @@ import textwrap from oslo.config import cfg +from nova.openstack.common import gettextutils from nova.openstack.common import importutils +gettextutils.install('nova') STROPT = "StrOpt" BOOLOPT = "BoolOpt" diff --git a/tools/config/generate_sample.sh b/tools/config/generate_sample.sh index 7b145e6882d5..643006f80ff0 100755 --- a/tools/config/generate_sample.sh +++ b/tools/config/generate_sample.sh @@ -18,12 +18,9 @@ while true; do echo "" echo "options:" echo "-h, --help show brief help" - echo "-b, --base-dir=DIR Project base directory (required)" - echo "-p, --package-name=NAME Project package name" - echo "-o, --output-dir=DIR File output directory" - echo "" - echo "To generate a new config, try:" - echo " ${0##*/} -b ./ -p nova -o etc/nova/" + echo "-b, --base-dir=DIR project base directory" + echo "-p, --package-name=NAME project package name" + echo "-o, --output-dir=DIR file output directory" exit 0 ;; -b|--base-dir) @@ -47,26 +44,43 @@ while true; do esac done -if [ -z $BASEDIR ] || ! [ -d $BASEDIR ] +BASEDIR=${BASEDIR:-`pwd`} +if ! [ -d $BASEDIR ] then echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1 +elif [[ $BASEDIR != /* ]] +then + BASEDIR=$(cd "$BASEDIR" && pwd) fi PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}} +TARGETDIR=$BASEDIR/$PACKAGENAME +if ! [ -d $TARGETDIR ] +then + echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1 +fi OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc} -if ! [ -d $OUTPUTDIR ] +# NOTE(bnemec): Some projects put their sample config in etc/, +# some in etc/$PACKAGENAME/ +if [ -d $OUTPUTDIR/$PACKAGENAME ] +then + OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME +elif ! [ -d $OUTPUTDIR ] then echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2 exit 1 fi BASEDIRESC=`echo $BASEDIR | sed -e 's/\//\\\\\//g'` -FILES=$(find $BASEDIR/$PACKAGENAME -type f -name "*.py" ! -path "*/tests/*" \ +FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" \ -exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u) export EVENTLET_NO_GREENDNS=yes +OS_VARS=$(set | sed -n '/^OS_/s/=[^=]*$//gp' | xargs) +[ "$OS_VARS" ] && eval "unset \$OS_VARS" + MODULEPATH=nova.openstack.common.config.generator OUTPUTFILE=$OUTPUTDIR/$PACKAGENAME.conf.sample python -m $MODULEPATH $FILES > $OUTPUTFILE