mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-29 18:44:43 +00:00
trace filtering
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2606 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
7df1caf58c
commit
e1e7055e79
1 changed files with 23 additions and 8 deletions
|
|
@ -28,6 +28,7 @@ import inspect
|
|||
import cStringIO as StringIO
|
||||
import linecache
|
||||
import sys
|
||||
import re
|
||||
try:
|
||||
import thread as _thread
|
||||
except ImportError:
|
||||
|
|
@ -40,9 +41,19 @@ except ImportError:
|
|||
|
||||
# tracing
|
||||
_trace_ignore = set()
|
||||
_trace_filter = set()
|
||||
|
||||
def trace_ignore (names):
|
||||
_trace_ignore.update(names)
|
||||
|
||||
def trace_filter (patterns):
|
||||
_trace_filter.update([re.compile(pat) for pat in patterns])
|
||||
|
||||
def trace_clear ():
|
||||
global _trace_ignore
|
||||
global _trace_filter
|
||||
_trace_ignore = set()
|
||||
_trace_filter = set()
|
||||
|
||||
def _traceit (frame, event, arg):
|
||||
"""
|
||||
|
|
@ -50,14 +61,18 @@ def _traceit (frame, event, arg):
|
|||
"""
|
||||
if event == "line":
|
||||
name = frame.f_globals["__name__"]
|
||||
if name not in _trace_ignore:
|
||||
lineno = frame.f_lineno
|
||||
filename = frame.f_globals["__file__"]
|
||||
if filename.endswith(".pyc") or filename.endswith(".pyo"):
|
||||
filename = filename[:-1]
|
||||
line = linecache.getline(filename, lineno)
|
||||
print "THREAD(%d) %s:%d: %s" % \
|
||||
(_thread.get_ident(), name, lineno, line.rstrip())
|
||||
if name in _trace_ignore:
|
||||
return _traceit
|
||||
for pat in _trace_filter:
|
||||
if not pat.match(name):
|
||||
return _traceit
|
||||
lineno = frame.f_lineno
|
||||
filename = frame.f_globals["__file__"]
|
||||
if filename.endswith(".pyc") or filename.endswith(".pyo"):
|
||||
filename = filename[:-1]
|
||||
line = linecache.getline(filename, lineno)
|
||||
print "THREAD(%d) %s:%d: %s" % \
|
||||
(_thread.get_ident(), name, lineno, line.rstrip())
|
||||
return _traceit
|
||||
|
||||
def trace ():
|
||||
|
|
|
|||
Loading…
Reference in a new issue