From 72450b4a93580d2d0d9fcc64f737ed45dab2c18f Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 25 Aug 2011 08:15:41 -0400 Subject: [PATCH] Move tools/tracer into the keystone code. Fixes ImportError's when running keystone as a .deb package. Change-Id: I194cdca188c5b916f222fd68ad41dc2671023aab --- bin/keystone | 2 +- bin/keystone-admin | 2 +- bin/keystone-auth | 2 +- keystone/common/config.py | 2 +- keystone/middleware/auth_token.py | 2 +- keystone/tools/__init__.py | 19 +++++++++++++++++++ {tools => keystone/tools}/tracer.py | 24 +++++++++++------------- 7 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 keystone/tools/__init__.py rename {tools => keystone/tools}/tracer.py (85%) diff --git a/bin/keystone b/bin/keystone index c47cda1d71..d6581228d0 100755 --- a/bin/keystone +++ b/bin/keystone @@ -34,7 +34,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')): sys.path.insert(0, possible_topdir) -import tools.tracer # @UnusedImport # module runs on import +import keystone.tools.tracer # @UnusedImport # module runs on import import keystone from keystone.common import config, wsgi diff --git a/bin/keystone-admin b/bin/keystone-admin index 3f617e67be..1b1236291a 100755 --- a/bin/keystone-admin +++ b/bin/keystone-admin @@ -34,7 +34,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')): sys.path.insert(0, possible_topdir) -import tools.tracer # @UnusedImport # module runs on import +import keystone.tools.tracer # @UnusedImport # module runs on import import keystone from keystone.common import config, wsgi diff --git a/bin/keystone-auth b/bin/keystone-auth index c5b798e32c..1717621670 100755 --- a/bin/keystone-auth +++ b/bin/keystone-auth @@ -34,7 +34,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')): sys.path.insert(0, possible_topdir) -import tools.tracer # @UnusedImport # module runs on import +import keystone.tools.tracer # @UnusedImport # module runs on import import keystone from keystone.common import config, wsgi diff --git a/keystone/common/config.py b/keystone/common/config.py index b2c47b3425..087831a140 100755 --- a/keystone/common/config.py +++ b/keystone/common/config.py @@ -84,7 +84,7 @@ for a config file.""") default="0.0.0.0", dest="bind_host", help="specifies host address to listen on "\ "(default is all or 0.0.0.0)") - # This one is handled by tools/tracer.py (if loaded) + # This one is handled by keystone/tools/tracer.py (if loaded) group.add_option('-t', '--trace-calls', default=False, dest="trace_calls", action="store_true", diff --git a/keystone/middleware/auth_token.py b/keystone/middleware/auth_token.py index 6eb5af253d..e0e993d8f1 100755 --- a/keystone/middleware/auth_token.py +++ b/keystone/middleware/auth_token.py @@ -58,7 +58,7 @@ from paste.deploy import loadapp from urlparse import urlparse from webob.exc import HTTPUnauthorized, HTTPUseProxy from webob.exc import Request, Response -import tools.tracer # @UnusedImport # module runs on import +import keystone.tools.tracer # @UnusedImport # module runs on import from keystone.common.bufferedhttp import http_connect_raw as http_connect diff --git a/keystone/tools/__init__.py b/keystone/tools/__init__.py new file mode 100644 index 0000000000..2baa83b13a --- /dev/null +++ b/keystone/tools/__init__.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. diff --git a/tools/tracer.py b/keystone/tools/tracer.py similarity index 85% rename from tools/tracer.py rename to keystone/tools/tracer.py index 2e4bb1b372..efdb4b0bec 100644 --- a/tools/tracer.py +++ b/keystone/tools/tracer.py @@ -45,33 +45,31 @@ import sys if '--trace-calls' in sys.argv: - stack_depth = 0 + STACK_DEPTH = 0 def localtrace(frame, event, arg): - global stack_depth + global STACK_DEPTH # pylint: disable=W0603 if event == "return": - stack_depth = stack_depth - 1 + STACK_DEPTH = STACK_DEPTH - 1 elif event == "exception": co = frame.f_code func_name = co.co_name line_no = frame.f_lineno - filename = co.co_filename - exc_type, exc_value, exc_traceback = arg + exc_type, exc_value, exc_traceback = arg # pylint: disable=W0612 print '\033[91m%sERROR: %s %s on line %s of %s\033[0m' % \ - (' ' * stack_depth, exc_type.__name__, exc_value, line_no, + (' ' * STACK_DEPTH, exc_type.__name__, exc_value, line_no, func_name) return None - def selectivetrace(frame, event, arg): - global stack_depth + def selectivetrace(frame, event, arg): # pylint: disable=R0911 + global STACK_DEPTH # pylint: disable=W0603 if event == "exception": co = frame.f_code func_name = co.co_name line_no = frame.f_lineno - filename = co.co_filename - exc_type, exc_value, exc_traceback = arg + exc_type, exc_value, exc_traceback = arg # pylint: disable=W0612 print '\033[91m%sERROR: %s %s on line %s of %s\033[0m' % \ - (' ' * stack_depth, exc_type.__name__, exc_value, line_no, + (' ' * STACK_DEPTH, exc_type.__name__, exc_value, line_no, func_name) if event != 'call': return @@ -105,10 +103,10 @@ if '--trace-calls' in sys.argv: caller_filename = caller.f_code.co_filename.replace( possible_topdir, '') print '%s%s::%s:%s (from %s:%s)' % \ - (' ' * stack_depth, func_filename, func_name, func_line_no, + (' ' * STACK_DEPTH, func_filename, func_name, func_line_no, caller_filename, caller_line_no) - stack_depth = stack_depth + 1 + STACK_DEPTH = STACK_DEPTH + 1 return localtrace sys.settrace(selectivetrace)