Allow generate_sample.sh to be run from toplevel dir

I hit an issue where extract_opts.py couldn't import importutils
since it's not in my sys.path, so it's clear we need to set
PYTHONPATH before running.

The whole business of running the tool from the tools/conf dir
is fairly awkward, so change it to run from the top-level dir
instead.

Change-Id: I89b4d874a6ee3732234a9704a8ee6001a293ed71
This commit is contained in:
Mark McLoughlin 2012-08-23 10:37:38 +01:00
parent 9fecad9e6f
commit 46de1cc267
3 changed files with 17 additions and 8 deletions

9
tools/conf/README Normal file
View File

@ -0,0 +1,9 @@
This tool is used to generate etc/nova/nova.conf.sample
Run it from the top-level working directory i.e.
$> ./tools/conf/generate_sample.sh
Watch out for warnings about modules like libvirt, qpid and zmq not
being found - these warnings are significant because they result
in options not appearing in the generated config file.

View File

@ -41,7 +41,7 @@ OPTION_REGEX = re.compile(r"(%s)" % "|".join([STROPT, BOOLOPT, INTOPT,
OPTION_HELP_INDENT = "####"
PY_EXT = ".py"
BASEDIR = os.path.abspath(os.path.dirname(__file__) + "../../")
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
WORDWRAP_WIDTH = 60
@ -50,8 +50,8 @@ def main(srcfiles):
'', '[DEFAULT]', ''])
mods_by_pkg = dict()
for filepath in srcfiles:
pkg_name = filepath.split(os.sep)[3]
mod_str = '.'.join(['.'.join(filepath.split(os.sep)[2:-1]),
pkg_name = filepath.split(os.sep)[1]
mod_str = '.'.join(['.'.join(filepath.split(os.sep)[:-1]),
os.path.basename(filepath).split('.')[0]])
mods_by_pkg.setdefault(pkg_name, list()).append(mod_str)
# NOTE(lzyeval): place top level modules before packages

View File

@ -16,10 +16,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
pushd $(cd $(dirname "$0") && pwd) >/dev/null
find ../../nova -type f -name "*.py" ! -path "../../nova/tests/*" -exec \
grep -l "Opt(" {} \; | sort -u | xargs python extract_opts.py > \
../../etc/nova/nova.conf.sample
FILES=$(find nova -type f -name "*.py" ! -path "nova/tests/*" -exec \
grep -l "Opt(" {} \; | sort -u)
popd >/dev/null
PYTHONPATH=./:${PYTHONPATH} \
python $(dirname "$0")/extract_opts.py ${FILES} > \
etc/nova/nova.conf.sample