blob: 20ddfbb5b7a3048dcc86a5bbf14dbdb1cdbf652d [file] [log] [blame]
Matthew Treinish547e8432013-10-24 19:50:49 +00001#!/usr/bin/env bash
2
3print_hint() {
4 echo "Try \`${0##*/} --help' for more information." >&2
5}
6
Matthew Treinish90ac9142014-03-17 14:58:37 +00007PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \
8 --long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@")
Matthew Treinish547e8432013-10-24 19:50:49 +00009
10if [ $? != 0 ] ; then print_hint ; exit 1 ; fi
11
12eval set -- "$PARSED_OPTIONS"
13
14while true; do
15 case "$1" in
16 -h|--help)
17 echo "${0##*/} [options]"
18 echo ""
19 echo "options:"
20 echo "-h, --help show brief help"
21 echo "-b, --base-dir=DIR project base directory"
22 echo "-p, --package-name=NAME project package name"
23 echo "-o, --output-dir=DIR file output directory"
Matthew Treinish90ac9142014-03-17 14:58:37 +000024 echo "-m, --module=MOD extra python module to interrogate for options"
25 echo "-l, --library=LIB extra library that registers options for discovery"
Matthew Treinish547e8432013-10-24 19:50:49 +000026 exit 0
27 ;;
28 -b|--base-dir)
29 shift
30 BASEDIR=`echo $1 | sed -e 's/\/*$//g'`
31 shift
32 ;;
33 -p|--package-name)
34 shift
35 PACKAGENAME=`echo $1`
36 shift
37 ;;
38 -o|--output-dir)
39 shift
40 OUTPUTDIR=`echo $1 | sed -e 's/\/*$//g'`
41 shift
42 ;;
Matthew Treinish90ac9142014-03-17 14:58:37 +000043 -m|--module)
44 shift
45 MODULES="$MODULES -m $1"
46 shift
47 ;;
48 -l|--library)
49 shift
50 LIBRARIES="$LIBRARIES -l $1"
51 shift
52 ;;
Matthew Treinish547e8432013-10-24 19:50:49 +000053 --)
54 break
55 ;;
56 esac
57done
58
59BASEDIR=${BASEDIR:-`pwd`}
60if ! [ -d $BASEDIR ]
61then
62 echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1
63elif [[ $BASEDIR != /* ]]
64then
65 BASEDIR=$(cd "$BASEDIR" && pwd)
66fi
67
Matthew Treinish90ac9142014-03-17 14:58:37 +000068PACKAGENAME=${PACKAGENAME:-$(python setup.py --name)}
Matthew Treinish547e8432013-10-24 19:50:49 +000069TARGETDIR=$BASEDIR/$PACKAGENAME
70if ! [ -d $TARGETDIR ]
71then
72 echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1
73fi
74
75OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc}
76# NOTE(bnemec): Some projects put their sample config in etc/,
77# some in etc/$PACKAGENAME/
78if [ -d $OUTPUTDIR/$PACKAGENAME ]
79then
80 OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME
81elif ! [ -d $OUTPUTDIR ]
82then
83 echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2
84 exit 1
85fi
86
87BASEDIRESC=`echo $BASEDIR | sed -e 's/\//\\\\\//g'`
88find $TARGETDIR -type f -name "*.pyc" -delete
89FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" \
90 -exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u)
91
Matthew Treinish90ac9142014-03-17 14:58:37 +000092RC_FILE="`dirname $0`/oslo.config.generator.rc"
93if test -r "$RC_FILE"
Matthew Treinish547e8432013-10-24 19:50:49 +000094then
Matthew Treinish90ac9142014-03-17 14:58:37 +000095 source "$RC_FILE"
Matthew Treinish547e8432013-10-24 19:50:49 +000096fi
97
Matthew Treinish90ac9142014-03-17 14:58:37 +000098for mod in ${TEMPEST_CONFIG_GENERATOR_EXTRA_MODULES}; do
99 MODULES="$MODULES -m $mod"
100done
101
102for lib in ${TEMPEST_CONFIG_GENERATOR_EXTRA_LIBRARIES}; do
103 LIBRARIES="$LIBRARIES -l $lib"
104done
105
Matthew Treinish547e8432013-10-24 19:50:49 +0000106export EVENTLET_NO_GREENDNS=yes
107
108OS_VARS=$(set | sed -n '/^OS_/s/=[^=]*$//gp' | xargs)
109[ "$OS_VARS" ] && eval "unset \$OS_VARS"
110DEFAULT_MODULEPATH=tempest.openstack.common.config.generator
111MODULEPATH=${MODULEPATH:-$DEFAULT_MODULEPATH}
112OUTPUTFILE=$OUTPUTDIR/$PACKAGENAME.conf.sample
Matthew Treinish90ac9142014-03-17 14:58:37 +0000113python -m $MODULEPATH $MODULES $LIBRARIES $FILES > $OUTPUTFILE
Sean Daguefc691e32014-01-03 08:51:54 -0500114
115# Hook to allow projects to append custom config file snippets
116CONCAT_FILES=$(ls $BASEDIR/tools/config/*.conf.sample 2>/dev/null)
117for CONCAT_FILE in $CONCAT_FILES; do
118 cat $CONCAT_FILE >> $OUTPUTFILE
119done