Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | print_hint() { |
| 4 | echo "Try \`${0##*/} --help' for more information." >&2 |
| 5 | } |
| 6 | |
Matthew Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 7 | PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:m:l:o: \ |
| 8 | --long help,base-dir:,package-name:,output-dir:,module:,library: -- "$@") |
Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 9 | |
| 10 | if [ $? != 0 ] ; then print_hint ; exit 1 ; fi |
| 11 | |
| 12 | eval set -- "$PARSED_OPTIONS" |
| 13 | |
| 14 | while 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 Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 24 | echo "-m, --module=MOD extra python module to interrogate for options" |
| 25 | echo "-l, --library=LIB extra library that registers options for discovery" |
Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 26 | 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 Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 43 | -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 Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 53 | --) |
| 54 | break |
| 55 | ;; |
| 56 | esac |
| 57 | done |
| 58 | |
| 59 | BASEDIR=${BASEDIR:-`pwd`} |
| 60 | if ! [ -d $BASEDIR ] |
| 61 | then |
| 62 | echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1 |
| 63 | elif [[ $BASEDIR != /* ]] |
| 64 | then |
| 65 | BASEDIR=$(cd "$BASEDIR" && pwd) |
| 66 | fi |
| 67 | |
Matthew Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 68 | PACKAGENAME=${PACKAGENAME:-$(python setup.py --name)} |
Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 69 | TARGETDIR=$BASEDIR/$PACKAGENAME |
| 70 | if ! [ -d $TARGETDIR ] |
| 71 | then |
| 72 | echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1 |
| 73 | fi |
| 74 | |
| 75 | OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc} |
| 76 | # NOTE(bnemec): Some projects put their sample config in etc/, |
| 77 | # some in etc/$PACKAGENAME/ |
| 78 | if [ -d $OUTPUTDIR/$PACKAGENAME ] |
| 79 | then |
| 80 | OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME |
| 81 | elif ! [ -d $OUTPUTDIR ] |
| 82 | then |
| 83 | echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2 |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | BASEDIRESC=`echo $BASEDIR | sed -e 's/\//\\\\\//g'` |
| 88 | find $TARGETDIR -type f -name "*.pyc" -delete |
| 89 | FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" \ |
| 90 | -exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u) |
| 91 | |
Matthew Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 92 | RC_FILE="`dirname $0`/oslo.config.generator.rc" |
| 93 | if test -r "$RC_FILE" |
Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 94 | then |
Matthew Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 95 | source "$RC_FILE" |
Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 96 | fi |
| 97 | |
Matthew Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 98 | for mod in ${TEMPEST_CONFIG_GENERATOR_EXTRA_MODULES}; do |
| 99 | MODULES="$MODULES -m $mod" |
| 100 | done |
| 101 | |
| 102 | for lib in ${TEMPEST_CONFIG_GENERATOR_EXTRA_LIBRARIES}; do |
| 103 | LIBRARIES="$LIBRARIES -l $lib" |
| 104 | done |
| 105 | |
Matthew Treinish | 547e843 | 2013-10-24 19:50:49 +0000 | [diff] [blame] | 106 | export EVENTLET_NO_GREENDNS=yes |
| 107 | |
| 108 | OS_VARS=$(set | sed -n '/^OS_/s/=[^=]*$//gp' | xargs) |
| 109 | [ "$OS_VARS" ] && eval "unset \$OS_VARS" |
| 110 | DEFAULT_MODULEPATH=tempest.openstack.common.config.generator |
| 111 | MODULEPATH=${MODULEPATH:-$DEFAULT_MODULEPATH} |
| 112 | OUTPUTFILE=$OUTPUTDIR/$PACKAGENAME.conf.sample |
Matthew Treinish | 90ac914 | 2014-03-17 14:58:37 +0000 | [diff] [blame] | 113 | python -m $MODULEPATH $MODULES $LIBRARIES $FILES > $OUTPUTFILE |
Sean Dague | fc691e3 | 2014-01-03 08:51:54 -0500 | [diff] [blame] | 114 | |
| 115 | # Hook to allow projects to append custom config file snippets |
| 116 | CONCAT_FILES=$(ls $BASEDIR/tools/config/*.conf.sample 2>/dev/null) |
| 117 | for CONCAT_FILE in $CONCAT_FILES; do |
| 118 | cat $CONCAT_FILE >> $OUTPUTFILE |
| 119 | done |