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 | |
| 7 | PARSED_OPTIONS=$(getopt -n "${0##*/}" -o hb:p:o: \ |
| 8 | --long help,base-dir:,package-name:,output-dir: -- "$@") |
| 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" |
| 24 | exit 0 |
| 25 | ;; |
| 26 | -b|--base-dir) |
| 27 | shift |
| 28 | BASEDIR=`echo $1 | sed -e 's/\/*$//g'` |
| 29 | shift |
| 30 | ;; |
| 31 | -p|--package-name) |
| 32 | shift |
| 33 | PACKAGENAME=`echo $1` |
| 34 | shift |
| 35 | ;; |
| 36 | -o|--output-dir) |
| 37 | shift |
| 38 | OUTPUTDIR=`echo $1 | sed -e 's/\/*$//g'` |
| 39 | shift |
| 40 | ;; |
| 41 | --) |
| 42 | break |
| 43 | ;; |
| 44 | esac |
| 45 | done |
| 46 | |
| 47 | BASEDIR=${BASEDIR:-`pwd`} |
| 48 | if ! [ -d $BASEDIR ] |
| 49 | then |
| 50 | echo "${0##*/}: missing project base directory" >&2 ; print_hint ; exit 1 |
| 51 | elif [[ $BASEDIR != /* ]] |
| 52 | then |
| 53 | BASEDIR=$(cd "$BASEDIR" && pwd) |
| 54 | fi |
| 55 | |
| 56 | PACKAGENAME=${PACKAGENAME:-${BASEDIR##*/}} |
| 57 | TARGETDIR=$BASEDIR/$PACKAGENAME |
| 58 | if ! [ -d $TARGETDIR ] |
| 59 | then |
| 60 | echo "${0##*/}: invalid project package name" >&2 ; print_hint ; exit 1 |
| 61 | fi |
| 62 | |
| 63 | OUTPUTDIR=${OUTPUTDIR:-$BASEDIR/etc} |
| 64 | # NOTE(bnemec): Some projects put their sample config in etc/, |
| 65 | # some in etc/$PACKAGENAME/ |
| 66 | if [ -d $OUTPUTDIR/$PACKAGENAME ] |
| 67 | then |
| 68 | OUTPUTDIR=$OUTPUTDIR/$PACKAGENAME |
| 69 | elif ! [ -d $OUTPUTDIR ] |
| 70 | then |
| 71 | echo "${0##*/}: cannot access \`$OUTPUTDIR': No such file or directory" >&2 |
| 72 | exit 1 |
| 73 | fi |
| 74 | |
| 75 | BASEDIRESC=`echo $BASEDIR | sed -e 's/\//\\\\\//g'` |
| 76 | find $TARGETDIR -type f -name "*.pyc" -delete |
| 77 | FILES=$(find $TARGETDIR -type f -name "*.py" ! -path "*/tests/*" \ |
| 78 | -exec grep -l "Opt(" {} + | sed -e "s/^$BASEDIRESC\///g" | sort -u) |
| 79 | |
| 80 | EXTRA_MODULES_FILE="`dirname $0`/oslo.config.generator.rc" |
| 81 | if test -r "$EXTRA_MODULES_FILE" |
| 82 | then |
| 83 | source "$EXTRA_MODULES_FILE" |
| 84 | fi |
| 85 | |
| 86 | export EVENTLET_NO_GREENDNS=yes |
| 87 | |
| 88 | OS_VARS=$(set | sed -n '/^OS_/s/=[^=]*$//gp' | xargs) |
| 89 | [ "$OS_VARS" ] && eval "unset \$OS_VARS" |
| 90 | DEFAULT_MODULEPATH=tempest.openstack.common.config.generator |
| 91 | MODULEPATH=${MODULEPATH:-$DEFAULT_MODULEPATH} |
| 92 | OUTPUTFILE=$OUTPUTDIR/$PACKAGENAME.conf.sample |
| 93 | python -m $MODULEPATH $FILES > $OUTPUTFILE |