Move tools/tracer into the keystone code.

Fixes ImportError's when running keystone as a .deb package.

Change-Id: I194cdca188c5b916f222fd68ad41dc2671023aab
This commit is contained in:
Dan Prince 2011-08-25 08:15:41 -04:00
parent 4f16376c2d
commit 72450b4a93
7 changed files with 35 additions and 18 deletions

View File

@ -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')): if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
sys.path.insert(0, possible_topdir) 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 import keystone
from keystone.common import config, wsgi from keystone.common import config, wsgi

View File

@ -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')): if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
sys.path.insert(0, possible_topdir) 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 import keystone
from keystone.common import config, wsgi from keystone.common import config, wsgi

View File

@ -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')): if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
sys.path.insert(0, possible_topdir) 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 import keystone
from keystone.common import config, wsgi from keystone.common import config, wsgi

View File

@ -84,7 +84,7 @@ for a config file.""")
default="0.0.0.0", dest="bind_host", default="0.0.0.0", dest="bind_host",
help="specifies host address to listen on "\ help="specifies host address to listen on "\
"(default is all or 0.0.0.0)") "(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, group.add_option('-t', '--trace-calls', default=False,
dest="trace_calls", dest="trace_calls",
action="store_true", action="store_true",

View File

@ -58,7 +58,7 @@ from paste.deploy import loadapp
from urlparse import urlparse from urlparse import urlparse
from webob.exc import HTTPUnauthorized, HTTPUseProxy from webob.exc import HTTPUnauthorized, HTTPUseProxy
from webob.exc import Request, Response 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 from keystone.common.bufferedhttp import http_connect_raw as http_connect

View File

@ -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.

View File

@ -45,33 +45,31 @@ import sys
if '--trace-calls' in sys.argv: if '--trace-calls' in sys.argv:
stack_depth = 0 STACK_DEPTH = 0
def localtrace(frame, event, arg): def localtrace(frame, event, arg):
global stack_depth global STACK_DEPTH # pylint: disable=W0603
if event == "return": if event == "return":
stack_depth = stack_depth - 1 STACK_DEPTH = STACK_DEPTH - 1
elif event == "exception": elif event == "exception":
co = frame.f_code co = frame.f_code
func_name = co.co_name func_name = co.co_name
line_no = frame.f_lineno line_no = frame.f_lineno
filename = co.co_filename exc_type, exc_value, exc_traceback = arg # pylint: disable=W0612
exc_type, exc_value, exc_traceback = arg
print '\033[91m%sERROR: %s %s on line %s of %s\033[0m' % \ 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) func_name)
return None return None
def selectivetrace(frame, event, arg): def selectivetrace(frame, event, arg): # pylint: disable=R0911
global stack_depth global STACK_DEPTH # pylint: disable=W0603
if event == "exception": if event == "exception":
co = frame.f_code co = frame.f_code
func_name = co.co_name func_name = co.co_name
line_no = frame.f_lineno line_no = frame.f_lineno
filename = co.co_filename exc_type, exc_value, exc_traceback = arg # pylint: disable=W0612
exc_type, exc_value, exc_traceback = arg
print '\033[91m%sERROR: %s %s on line %s of %s\033[0m' % \ 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) func_name)
if event != 'call': if event != 'call':
return return
@ -105,10 +103,10 @@ if '--trace-calls' in sys.argv:
caller_filename = caller.f_code.co_filename.replace( caller_filename = caller.f_code.co_filename.replace(
possible_topdir, '') possible_topdir, '')
print '%s%s::%s:%s (from %s:%s)' % \ 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) caller_filename, caller_line_no)
stack_depth = stack_depth + 1 STACK_DEPTH = STACK_DEPTH + 1
return localtrace return localtrace
sys.settrace(selectivetrace) sys.settrace(selectivetrace)