diff options
| author | Monty Taylor <mordred@inaugust.com> | 2011-09-20 12:25:59 -0400 |
|---|---|---|
| committer | Monty Taylor <mordred@inaugust.com> | 2011-09-20 12:33:36 -0400 |
| commit | acb2d074d3e0c08d31e1fd3df5ee2da306bb5ab5 (patch) | |
| tree | 061f5d3d58b647aaf5d9841bb616a8d5cc4970c6 | |
| parent | eee307a8967d5bef6c45b3e4b0ba4a9d8e855158 (diff) | |
| download | keystone-acb2d074d3e0c08d31e1fd3df5ee2da306bb5ab5.tar.gz keystone-acb2d074d3e0c08d31e1fd3df5ee2da306bb5ab5.tar.xz keystone-acb2d074d3e0c08d31e1fd3df5ee2da306bb5ab5.zip | |
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
| -rwxr-xr-x | bin/keystone-import | 25 | ||||
| -rw-r--r-- | keystone/manage/__init__.py | 11 |
2 files changed, 28 insertions, 8 deletions
diff --git a/bin/keystone-import b/bin/keystone-import index 33e0d52e..54170c52 100755 --- a/bin/keystone-import +++ b/bin/keystone-import @@ -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) diff --git a/keystone/manage/__init__.py b/keystone/manage/__init__.py index 42322ff6..3d24c0aa 100644 --- a/keystone/manage/__init__.py +++ b/keystone/manage/__init__.py @@ -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) |
