Fixed path issues with keystone-import.

Made it a python script so that we wouldn't be dealing
with load path issues - or execing a python script a
bazillion times.

Change-Id: Ib0c1b74e8bc2b2f96962e1cee5dc20efff642ad3
This commit is contained in:
Monty Taylor 2011-09-20 12:25:59 -04:00
parent eee307a896
commit acb2d074d3
2 changed files with 28 additions and 8 deletions

View File

@ -1,4 +1,4 @@
#! /usr/bin/env bash
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
@ -19,6 +19,23 @@
# This file is to read a export file from Nova that will import users, tenants and EC2 credentials
# The file should be in the keystone-manage format
while read line; do
./bin/keystone-manage $line
done < $1
import os
import sys
import shlex
# If ../../keystone/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
sys.path.insert(0, possible_topdir)
import keystone.manage
with open(sys.argv[1], 'r') as line:
try:
keystone.manage.main(shlex.split(line))
except Exception as exc:
# Main prints all of the errors we need
sys.exit(1)

View File

@ -229,9 +229,9 @@ def process(*args):
print ("ERROR: unrecognized command %s %s" % (object_type, command))
def main():
def main(args=None):
try:
process(*parse_args())
process(*parse_args(args))
except optparse.OptParseError as exc:
print >> sys.stderr, exc
sys.exit(2)
@ -244,8 +244,11 @@ def main():
else:
print "ERROR: %s: %s" % (exc.args[0], info)
logging.error(exc.args[0], exc_info=info)
sys.exit(1)
raise exc
if __name__ == '__main__':
main()
try:
main()
except Exception as exc:
sys.exit(1)