@@ -0,0 +1,1846 @@
+%0A%0A%0Aimport sys%0Aimport string%0Aimport linecache%0A%0A_trace_external = False%0A%0A%22%22%22%0A%0A  idea from http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html%0A%0A%0A  This module will trace all saga level calls, printing each line as it is being%0A  executed.  It will not print traces for system libraries (i.e. modules which%0A  are not in the saga namespace), but will indicate when the code descents to%0A  the system level.%0A%0A  Python system traces are not following Python's %60exec()%60 call (and%0A  derivatives), so the resulting trace may be incomplete.  In particular, the%0A  trace will not walk down onto adaptor level, yet -- later of this utility may%0A  do that.  Right now it is mostly useful to trace calls *within* adaptors.%0A%0A  Use like this::%0A%0A      def my_call (url) :%0A%0A          import saga.utils.tracer%0A          saga.utils.tracer.trace ()%0A%0A          f = saga.filesystem.File (url)%0A          print f.size()%0A%0A          saga.utils.tracer.untrace ()%0A%0A%22%22%22%0A%0A%0Adef _tracer (frame, event, arg) :%0A%0A    global _trace_external%0A%0A  # if  event == %22call%22 :%0A    if  event == %22line%22 :%0A%0A        filename = frame.f_globals%5B%22__file__%22%5D%0A        lineno   = frame.f_lineno%0A        %0A        if (filename.endswith (%22.pyc%22) or%0A            filename.endswith (%22.pyo%22) ) :%0A            filename = filename%5B:-1%5D%0A%0A        line = linecache.getline (filename, lineno)%0A        idx  = string.find       (filename, %22/saga/%22)%0A%0A        if idx %3E= 0 :%0A%0A            name = filename%5Bidx:%5D%0A            print %22%25-60s:%254d: %25s%22 %25 (name, lineno, line.rstrip ())%0A            _trace_external = False%0A%0A        else :%0A%0A            if not _trace_external :%0A                print %22--%3E %25-56s:%254s: %25s%22 %25 (filename, lineno, line.rstrip ())%0A            _trace_external = True%0A%0A%0A    return _tracer%0A%0Adef trace () :%0A    sys.settrace (_tracer)%0A%0Adef untrace () :%0A    sys.settrace (None)%0A%0A

add tracer utility to support adaptor debugging