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