Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: trace.py
#! /usr/bin/python2.7
[0] Fix | Delete
[1] Fix | Delete
# portions copyright 2001, Autonomous Zones Industries, Inc., all rights...
[2] Fix | Delete
# err... reserved and offered to the public under the terms of the
[3] Fix | Delete
# Python 2.2 license.
[4] Fix | Delete
# Author: Zooko O'Whielacronx
[5] Fix | Delete
# http://zooko.com/
[6] Fix | Delete
# mailto:zooko@zooko.com
[7] Fix | Delete
#
[8] Fix | Delete
# Copyright 2000, Mojam Media, Inc., all rights reserved.
[9] Fix | Delete
# Author: Skip Montanaro
[10] Fix | Delete
#
[11] Fix | Delete
# Copyright 1999, Bioreason, Inc., all rights reserved.
[12] Fix | Delete
# Author: Andrew Dalke
[13] Fix | Delete
#
[14] Fix | Delete
# Copyright 1995-1997, Automatrix, Inc., all rights reserved.
[15] Fix | Delete
# Author: Skip Montanaro
[16] Fix | Delete
#
[17] Fix | Delete
# Copyright 1991-1995, Stichting Mathematisch Centrum, all rights reserved.
[18] Fix | Delete
#
[19] Fix | Delete
#
[20] Fix | Delete
# Permission to use, copy, modify, and distribute this Python software and
[21] Fix | Delete
# its associated documentation for any purpose without fee is hereby
[22] Fix | Delete
# granted, provided that the above copyright notice appears in all copies,
[23] Fix | Delete
# and that both that copyright notice and this permission notice appear in
[24] Fix | Delete
# supporting documentation, and that the name of neither Automatrix,
[25] Fix | Delete
# Bioreason or Mojam Media be used in advertising or publicity pertaining to
[26] Fix | Delete
# distribution of the software without specific, written prior permission.
[27] Fix | Delete
#
[28] Fix | Delete
"""program/module to trace Python program or function execution
[29] Fix | Delete
[30] Fix | Delete
Sample use, command line:
[31] Fix | Delete
trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs
[32] Fix | Delete
trace.py -t --ignore-dir '$prefix' spam.py eggs
[33] Fix | Delete
trace.py --trackcalls spam.py eggs
[34] Fix | Delete
[35] Fix | Delete
Sample use, programmatically
[36] Fix | Delete
import sys
[37] Fix | Delete
[38] Fix | Delete
# create a Trace object, telling it what to ignore, and whether to
[39] Fix | Delete
# do tracing or line-counting or both.
[40] Fix | Delete
tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0,
[41] Fix | Delete
count=1)
[42] Fix | Delete
# run the new command using the given tracer
[43] Fix | Delete
tracer.run('main()')
[44] Fix | Delete
# make a report, placing output in /tmp
[45] Fix | Delete
r = tracer.results()
[46] Fix | Delete
r.write_results(show_missing=True, coverdir="/tmp")
[47] Fix | Delete
"""
[48] Fix | Delete
[49] Fix | Delete
import linecache
[50] Fix | Delete
import os
[51] Fix | Delete
import re
[52] Fix | Delete
import sys
[53] Fix | Delete
import time
[54] Fix | Delete
import token
[55] Fix | Delete
import tokenize
[56] Fix | Delete
import inspect
[57] Fix | Delete
import gc
[58] Fix | Delete
import dis
[59] Fix | Delete
try:
[60] Fix | Delete
import cPickle
[61] Fix | Delete
pickle = cPickle
[62] Fix | Delete
except ImportError:
[63] Fix | Delete
import pickle
[64] Fix | Delete
[65] Fix | Delete
try:
[66] Fix | Delete
import threading
[67] Fix | Delete
except ImportError:
[68] Fix | Delete
_settrace = sys.settrace
[69] Fix | Delete
[70] Fix | Delete
def _unsettrace():
[71] Fix | Delete
sys.settrace(None)
[72] Fix | Delete
else:
[73] Fix | Delete
def _settrace(func):
[74] Fix | Delete
threading.settrace(func)
[75] Fix | Delete
sys.settrace(func)
[76] Fix | Delete
[77] Fix | Delete
def _unsettrace():
[78] Fix | Delete
sys.settrace(None)
[79] Fix | Delete
threading.settrace(None)
[80] Fix | Delete
[81] Fix | Delete
def usage(outfile):
[82] Fix | Delete
outfile.write("""Usage: %s [OPTIONS] <file> [ARGS]
[83] Fix | Delete
[84] Fix | Delete
Meta-options:
[85] Fix | Delete
--help Display this help then exit.
[86] Fix | Delete
--version Output version information then exit.
[87] Fix | Delete
[88] Fix | Delete
Otherwise, exactly one of the following three options must be given:
[89] Fix | Delete
-t, --trace Print each line to sys.stdout before it is executed.
[90] Fix | Delete
-c, --count Count the number of times each line is executed
[91] Fix | Delete
and write the counts to <module>.cover for each
[92] Fix | Delete
module executed, in the module's directory.
[93] Fix | Delete
See also `--coverdir', `--file', `--no-report' below.
[94] Fix | Delete
-l, --listfuncs Keep track of which functions are executed at least
[95] Fix | Delete
once and write the results to sys.stdout after the
[96] Fix | Delete
program exits.
[97] Fix | Delete
-T, --trackcalls Keep track of caller/called pairs and write the
[98] Fix | Delete
results to sys.stdout after the program exits.
[99] Fix | Delete
-r, --report Generate a report from a counts file; do not execute
[100] Fix | Delete
any code. `--file' must specify the results file to
[101] Fix | Delete
read, which must have been created in a previous run
[102] Fix | Delete
with `--count --file=FILE'.
[103] Fix | Delete
[104] Fix | Delete
Modifiers:
[105] Fix | Delete
-f, --file=<file> File to accumulate counts over several runs.
[106] Fix | Delete
-R, --no-report Do not generate the coverage report files.
[107] Fix | Delete
Useful if you want to accumulate over several runs.
[108] Fix | Delete
-C, --coverdir=<dir> Directory where the report files. The coverage
[109] Fix | Delete
report for <package>.<module> is written to file
[110] Fix | Delete
<dir>/<package>/<module>.cover.
[111] Fix | Delete
-m, --missing Annotate executable lines that were not executed
[112] Fix | Delete
with '>>>>>> '.
[113] Fix | Delete
-s, --summary Write a brief summary on stdout for each file.
[114] Fix | Delete
(Can only be used with --count or --report.)
[115] Fix | Delete
-g, --timing Prefix each line with the time since the program started.
[116] Fix | Delete
Only used while tracing.
[117] Fix | Delete
[118] Fix | Delete
Filters, may be repeated multiple times:
[119] Fix | Delete
--ignore-module=<mod> Ignore the given module(s) and its submodules
[120] Fix | Delete
(if it is a package). Accepts comma separated
[121] Fix | Delete
list of module names
[122] Fix | Delete
--ignore-dir=<dir> Ignore files in the given directory (multiple
[123] Fix | Delete
directories can be joined by os.pathsep).
[124] Fix | Delete
""" % sys.argv[0])
[125] Fix | Delete
[126] Fix | Delete
PRAGMA_NOCOVER = "#pragma NO COVER"
[127] Fix | Delete
[128] Fix | Delete
# Simple rx to find lines with no code.
[129] Fix | Delete
rx_blank = re.compile(r'^\s*(#.*)?$')
[130] Fix | Delete
[131] Fix | Delete
class Ignore:
[132] Fix | Delete
def __init__(self, modules = None, dirs = None):
[133] Fix | Delete
self._mods = modules or []
[134] Fix | Delete
self._dirs = dirs or []
[135] Fix | Delete
[136] Fix | Delete
self._dirs = map(os.path.normpath, self._dirs)
[137] Fix | Delete
self._ignore = { '<string>': 1 }
[138] Fix | Delete
[139] Fix | Delete
def names(self, filename, modulename):
[140] Fix | Delete
if modulename in self._ignore:
[141] Fix | Delete
return self._ignore[modulename]
[142] Fix | Delete
[143] Fix | Delete
# haven't seen this one before, so see if the module name is
[144] Fix | Delete
# on the ignore list. Need to take some care since ignoring
[145] Fix | Delete
# "cmp" musn't mean ignoring "cmpcache" but ignoring
[146] Fix | Delete
# "Spam" must also mean ignoring "Spam.Eggs".
[147] Fix | Delete
for mod in self._mods:
[148] Fix | Delete
if mod == modulename: # Identical names, so ignore
[149] Fix | Delete
self._ignore[modulename] = 1
[150] Fix | Delete
return 1
[151] Fix | Delete
# check if the module is a proper submodule of something on
[152] Fix | Delete
# the ignore list
[153] Fix | Delete
n = len(mod)
[154] Fix | Delete
# (will not overflow since if the first n characters are the
[155] Fix | Delete
# same and the name has not already occurred, then the size
[156] Fix | Delete
# of "name" is greater than that of "mod")
[157] Fix | Delete
if mod == modulename[:n] and modulename[n] == '.':
[158] Fix | Delete
self._ignore[modulename] = 1
[159] Fix | Delete
return 1
[160] Fix | Delete
[161] Fix | Delete
# Now check that __file__ isn't in one of the directories
[162] Fix | Delete
if filename is None:
[163] Fix | Delete
# must be a built-in, so we must ignore
[164] Fix | Delete
self._ignore[modulename] = 1
[165] Fix | Delete
return 1
[166] Fix | Delete
[167] Fix | Delete
# Ignore a file when it contains one of the ignorable paths
[168] Fix | Delete
for d in self._dirs:
[169] Fix | Delete
# The '+ os.sep' is to ensure that d is a parent directory,
[170] Fix | Delete
# as compared to cases like:
[171] Fix | Delete
# d = "/usr/local"
[172] Fix | Delete
# filename = "/usr/local.py"
[173] Fix | Delete
# or
[174] Fix | Delete
# d = "/usr/local.py"
[175] Fix | Delete
# filename = "/usr/local.py"
[176] Fix | Delete
if filename.startswith(d + os.sep):
[177] Fix | Delete
self._ignore[modulename] = 1
[178] Fix | Delete
return 1
[179] Fix | Delete
[180] Fix | Delete
# Tried the different ways, so we don't ignore this module
[181] Fix | Delete
self._ignore[modulename] = 0
[182] Fix | Delete
return 0
[183] Fix | Delete
[184] Fix | Delete
def modname(path):
[185] Fix | Delete
"""Return a plausible module name for the patch."""
[186] Fix | Delete
[187] Fix | Delete
base = os.path.basename(path)
[188] Fix | Delete
filename, ext = os.path.splitext(base)
[189] Fix | Delete
return filename
[190] Fix | Delete
[191] Fix | Delete
def fullmodname(path):
[192] Fix | Delete
"""Return a plausible module name for the path."""
[193] Fix | Delete
[194] Fix | Delete
# If the file 'path' is part of a package, then the filename isn't
[195] Fix | Delete
# enough to uniquely identify it. Try to do the right thing by
[196] Fix | Delete
# looking in sys.path for the longest matching prefix. We'll
[197] Fix | Delete
# assume that the rest is the package name.
[198] Fix | Delete
[199] Fix | Delete
comparepath = os.path.normcase(path)
[200] Fix | Delete
longest = ""
[201] Fix | Delete
for dir in sys.path:
[202] Fix | Delete
dir = os.path.normcase(dir)
[203] Fix | Delete
if comparepath.startswith(dir) and comparepath[len(dir)] == os.sep:
[204] Fix | Delete
if len(dir) > len(longest):
[205] Fix | Delete
longest = dir
[206] Fix | Delete
[207] Fix | Delete
if longest:
[208] Fix | Delete
base = path[len(longest) + 1:]
[209] Fix | Delete
else:
[210] Fix | Delete
base = path
[211] Fix | Delete
# the drive letter is never part of the module name
[212] Fix | Delete
drive, base = os.path.splitdrive(base)
[213] Fix | Delete
base = base.replace(os.sep, ".")
[214] Fix | Delete
if os.altsep:
[215] Fix | Delete
base = base.replace(os.altsep, ".")
[216] Fix | Delete
filename, ext = os.path.splitext(base)
[217] Fix | Delete
return filename.lstrip(".")
[218] Fix | Delete
[219] Fix | Delete
class CoverageResults:
[220] Fix | Delete
def __init__(self, counts=None, calledfuncs=None, infile=None,
[221] Fix | Delete
callers=None, outfile=None):
[222] Fix | Delete
self.counts = counts
[223] Fix | Delete
if self.counts is None:
[224] Fix | Delete
self.counts = {}
[225] Fix | Delete
self.counter = self.counts.copy() # map (filename, lineno) to count
[226] Fix | Delete
self.calledfuncs = calledfuncs
[227] Fix | Delete
if self.calledfuncs is None:
[228] Fix | Delete
self.calledfuncs = {}
[229] Fix | Delete
self.calledfuncs = self.calledfuncs.copy()
[230] Fix | Delete
self.callers = callers
[231] Fix | Delete
if self.callers is None:
[232] Fix | Delete
self.callers = {}
[233] Fix | Delete
self.callers = self.callers.copy()
[234] Fix | Delete
self.infile = infile
[235] Fix | Delete
self.outfile = outfile
[236] Fix | Delete
if self.infile:
[237] Fix | Delete
# Try to merge existing counts file.
[238] Fix | Delete
try:
[239] Fix | Delete
counts, calledfuncs, callers = \
[240] Fix | Delete
pickle.load(open(self.infile, 'rb'))
[241] Fix | Delete
self.update(self.__class__(counts, calledfuncs, callers))
[242] Fix | Delete
except (IOError, EOFError, ValueError), err:
[243] Fix | Delete
print >> sys.stderr, ("Skipping counts file %r: %s"
[244] Fix | Delete
% (self.infile, err))
[245] Fix | Delete
[246] Fix | Delete
def update(self, other):
[247] Fix | Delete
"""Merge in the data from another CoverageResults"""
[248] Fix | Delete
counts = self.counts
[249] Fix | Delete
calledfuncs = self.calledfuncs
[250] Fix | Delete
callers = self.callers
[251] Fix | Delete
other_counts = other.counts
[252] Fix | Delete
other_calledfuncs = other.calledfuncs
[253] Fix | Delete
other_callers = other.callers
[254] Fix | Delete
[255] Fix | Delete
for key in other_counts.keys():
[256] Fix | Delete
counts[key] = counts.get(key, 0) + other_counts[key]
[257] Fix | Delete
[258] Fix | Delete
for key in other_calledfuncs.keys():
[259] Fix | Delete
calledfuncs[key] = 1
[260] Fix | Delete
[261] Fix | Delete
for key in other_callers.keys():
[262] Fix | Delete
callers[key] = 1
[263] Fix | Delete
[264] Fix | Delete
def write_results(self, show_missing=True, summary=False, coverdir=None):
[265] Fix | Delete
"""
[266] Fix | Delete
@param coverdir
[267] Fix | Delete
"""
[268] Fix | Delete
if self.calledfuncs:
[269] Fix | Delete
print
[270] Fix | Delete
print "functions called:"
[271] Fix | Delete
calls = self.calledfuncs.keys()
[272] Fix | Delete
calls.sort()
[273] Fix | Delete
for filename, modulename, funcname in calls:
[274] Fix | Delete
print ("filename: %s, modulename: %s, funcname: %s"
[275] Fix | Delete
% (filename, modulename, funcname))
[276] Fix | Delete
[277] Fix | Delete
if self.callers:
[278] Fix | Delete
print
[279] Fix | Delete
print "calling relationships:"
[280] Fix | Delete
calls = self.callers.keys()
[281] Fix | Delete
calls.sort()
[282] Fix | Delete
lastfile = lastcfile = ""
[283] Fix | Delete
for ((pfile, pmod, pfunc), (cfile, cmod, cfunc)) in calls:
[284] Fix | Delete
if pfile != lastfile:
[285] Fix | Delete
print
[286] Fix | Delete
print "***", pfile, "***"
[287] Fix | Delete
lastfile = pfile
[288] Fix | Delete
lastcfile = ""
[289] Fix | Delete
if cfile != pfile and lastcfile != cfile:
[290] Fix | Delete
print " -->", cfile
[291] Fix | Delete
lastcfile = cfile
[292] Fix | Delete
print " %s.%s -> %s.%s" % (pmod, pfunc, cmod, cfunc)
[293] Fix | Delete
[294] Fix | Delete
# turn the counts data ("(filename, lineno) = count") into something
[295] Fix | Delete
# accessible on a per-file basis
[296] Fix | Delete
per_file = {}
[297] Fix | Delete
for filename, lineno in self.counts.keys():
[298] Fix | Delete
lines_hit = per_file[filename] = per_file.get(filename, {})
[299] Fix | Delete
lines_hit[lineno] = self.counts[(filename, lineno)]
[300] Fix | Delete
[301] Fix | Delete
# accumulate summary info, if needed
[302] Fix | Delete
sums = {}
[303] Fix | Delete
[304] Fix | Delete
for filename, count in per_file.iteritems():
[305] Fix | Delete
# skip some "files" we don't care about...
[306] Fix | Delete
if filename == "<string>":
[307] Fix | Delete
continue
[308] Fix | Delete
if filename.startswith("<doctest "):
[309] Fix | Delete
continue
[310] Fix | Delete
[311] Fix | Delete
if filename.endswith((".pyc", ".pyo")):
[312] Fix | Delete
filename = filename[:-1]
[313] Fix | Delete
[314] Fix | Delete
if coverdir is None:
[315] Fix | Delete
dir = os.path.dirname(os.path.abspath(filename))
[316] Fix | Delete
modulename = modname(filename)
[317] Fix | Delete
else:
[318] Fix | Delete
dir = coverdir
[319] Fix | Delete
if not os.path.exists(dir):
[320] Fix | Delete
os.makedirs(dir)
[321] Fix | Delete
modulename = fullmodname(filename)
[322] Fix | Delete
[323] Fix | Delete
# If desired, get a list of the line numbers which represent
[324] Fix | Delete
# executable content (returned as a dict for better lookup speed)
[325] Fix | Delete
if show_missing:
[326] Fix | Delete
lnotab = find_executable_linenos(filename)
[327] Fix | Delete
else:
[328] Fix | Delete
lnotab = {}
[329] Fix | Delete
[330] Fix | Delete
source = linecache.getlines(filename)
[331] Fix | Delete
coverpath = os.path.join(dir, modulename + ".cover")
[332] Fix | Delete
n_hits, n_lines = self.write_results_file(coverpath, source,
[333] Fix | Delete
lnotab, count)
[334] Fix | Delete
[335] Fix | Delete
if summary and n_lines:
[336] Fix | Delete
percent = 100 * n_hits // n_lines
[337] Fix | Delete
sums[modulename] = n_lines, percent, modulename, filename
[338] Fix | Delete
[339] Fix | Delete
if summary and sums:
[340] Fix | Delete
mods = sums.keys()
[341] Fix | Delete
mods.sort()
[342] Fix | Delete
print "lines cov% module (path)"
[343] Fix | Delete
for m in mods:
[344] Fix | Delete
n_lines, percent, modulename, filename = sums[m]
[345] Fix | Delete
print "%5d %3d%% %s (%s)" % sums[m]
[346] Fix | Delete
[347] Fix | Delete
if self.outfile:
[348] Fix | Delete
# try and store counts and module info into self.outfile
[349] Fix | Delete
try:
[350] Fix | Delete
pickle.dump((self.counts, self.calledfuncs, self.callers),
[351] Fix | Delete
open(self.outfile, 'wb'), 1)
[352] Fix | Delete
except IOError, err:
[353] Fix | Delete
print >> sys.stderr, "Can't save counts files because %s" % err
[354] Fix | Delete
[355] Fix | Delete
def write_results_file(self, path, lines, lnotab, lines_hit):
[356] Fix | Delete
"""Return a coverage results file in path."""
[357] Fix | Delete
[358] Fix | Delete
try:
[359] Fix | Delete
outfile = open(path, "w")
[360] Fix | Delete
except IOError, err:
[361] Fix | Delete
print >> sys.stderr, ("trace: Could not open %r for writing: %s "
[362] Fix | Delete
"- skipping" % (path, err))
[363] Fix | Delete
return 0, 0
[364] Fix | Delete
[365] Fix | Delete
n_lines = 0
[366] Fix | Delete
n_hits = 0
[367] Fix | Delete
for i, line in enumerate(lines):
[368] Fix | Delete
lineno = i + 1
[369] Fix | Delete
# do the blank/comment match to try to mark more lines
[370] Fix | Delete
# (help the reader find stuff that hasn't been covered)
[371] Fix | Delete
if lineno in lines_hit:
[372] Fix | Delete
outfile.write("%5d: " % lines_hit[lineno])
[373] Fix | Delete
n_hits += 1
[374] Fix | Delete
n_lines += 1
[375] Fix | Delete
elif rx_blank.match(line):
[376] Fix | Delete
outfile.write(" ")
[377] Fix | Delete
else:
[378] Fix | Delete
# lines preceded by no marks weren't hit
[379] Fix | Delete
# Highlight them if so indicated, unless the line contains
[380] Fix | Delete
# #pragma: NO COVER
[381] Fix | Delete
if lineno in lnotab and not PRAGMA_NOCOVER in lines[i]:
[382] Fix | Delete
outfile.write(">>>>>> ")
[383] Fix | Delete
n_lines += 1
[384] Fix | Delete
else:
[385] Fix | Delete
outfile.write(" ")
[386] Fix | Delete
outfile.write(lines[i].expandtabs(8))
[387] Fix | Delete
outfile.close()
[388] Fix | Delete
[389] Fix | Delete
return n_hits, n_lines
[390] Fix | Delete
[391] Fix | Delete
def find_lines_from_code(code, strs):
[392] Fix | Delete
"""Return dict where keys are lines in the line number table."""
[393] Fix | Delete
linenos = {}
[394] Fix | Delete
[395] Fix | Delete
for _, lineno in dis.findlinestarts(code):
[396] Fix | Delete
if lineno not in strs:
[397] Fix | Delete
linenos[lineno] = 1
[398] Fix | Delete
[399] Fix | Delete
return linenos
[400] Fix | Delete
[401] Fix | Delete
def find_lines(code, strs):
[402] Fix | Delete
"""Return lineno dict for all code objects reachable from code."""
[403] Fix | Delete
# get all of the lineno information from the code of this scope level
[404] Fix | Delete
linenos = find_lines_from_code(code, strs)
[405] Fix | Delete
[406] Fix | Delete
# and check the constants for references to other code objects
[407] Fix | Delete
for c in code.co_consts:
[408] Fix | Delete
if inspect.iscode(c):
[409] Fix | Delete
# find another code object, so recurse into it
[410] Fix | Delete
linenos.update(find_lines(c, strs))
[411] Fix | Delete
return linenos
[412] Fix | Delete
[413] Fix | Delete
def find_strings(filename):
[414] Fix | Delete
"""Return a dict of possible docstring positions.
[415] Fix | Delete
[416] Fix | Delete
The dict maps line numbers to strings. There is an entry for
[417] Fix | Delete
line that contains only a string or a part of a triple-quoted
[418] Fix | Delete
string.
[419] Fix | Delete
"""
[420] Fix | Delete
d = {}
[421] Fix | Delete
# If the first token is a string, then it's the module docstring.
[422] Fix | Delete
# Add this special case so that the test in the loop passes.
[423] Fix | Delete
prev_ttype = token.INDENT
[424] Fix | Delete
f = open(filename)
[425] Fix | Delete
for ttype, tstr, start, end, line in tokenize.generate_tokens(f.readline):
[426] Fix | Delete
if ttype == token.STRING:
[427] Fix | Delete
if prev_ttype == token.INDENT:
[428] Fix | Delete
sline, scol = start
[429] Fix | Delete
eline, ecol = end
[430] Fix | Delete
for i in range(sline, eline + 1):
[431] Fix | Delete
d[i] = 1
[432] Fix | Delete
prev_ttype = ttype
[433] Fix | Delete
f.close()
[434] Fix | Delete
return d
[435] Fix | Delete
[436] Fix | Delete
def find_executable_linenos(filename):
[437] Fix | Delete
"""Return dict where keys are line numbers in the line number table."""
[438] Fix | Delete
try:
[439] Fix | Delete
prog = open(filename, "rU").read()
[440] Fix | Delete
except IOError, err:
[441] Fix | Delete
print >> sys.stderr, ("Not printing coverage data for %r: %s"
[442] Fix | Delete
% (filename, err))
[443] Fix | Delete
return {}
[444] Fix | Delete
code = compile(prog, filename, "exec")
[445] Fix | Delete
strs = find_strings(filename)
[446] Fix | Delete
return find_lines(code, strs)
[447] Fix | Delete
[448] Fix | Delete
class Trace:
[449] Fix | Delete
def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0,
[450] Fix | Delete
ignoremods=(), ignoredirs=(), infile=None, outfile=None,
[451] Fix | Delete
timing=False):
[452] Fix | Delete
"""
[453] Fix | Delete
@param count true iff it should count number of times each
[454] Fix | Delete
line is executed
[455] Fix | Delete
@param trace true iff it should print out each line that is
[456] Fix | Delete
being counted
[457] Fix | Delete
@param countfuncs true iff it should just output a list of
[458] Fix | Delete
(filename, modulename, funcname,) for functions
[459] Fix | Delete
that were called at least once; This overrides
[460] Fix | Delete
`count' and `trace'
[461] Fix | Delete
@param ignoremods a list of the names of modules to ignore
[462] Fix | Delete
@param ignoredirs a list of the names of directories to ignore
[463] Fix | Delete
all of the (recursive) contents of
[464] Fix | Delete
@param infile file from which to read stored counts to be
[465] Fix | Delete
added into the results
[466] Fix | Delete
@param outfile file in which to write the results
[467] Fix | Delete
@param timing true iff timing information be displayed
[468] Fix | Delete
"""
[469] Fix | Delete
self.infile = infile
[470] Fix | Delete
self.outfile = outfile
[471] Fix | Delete
self.ignore = Ignore(ignoremods, ignoredirs)
[472] Fix | Delete
self.counts = {} # keys are (filename, linenumber)
[473] Fix | Delete
self.blabbed = {} # for debugging
[474] Fix | Delete
self.pathtobasename = {} # for memoizing os.path.basename
[475] Fix | Delete
self.donothing = 0
[476] Fix | Delete
self.trace = trace
[477] Fix | Delete
self._calledfuncs = {}
[478] Fix | Delete
self._callers = {}
[479] Fix | Delete
self._caller_cache = {}
[480] Fix | Delete
self.start_time = None
[481] Fix | Delete
if timing:
[482] Fix | Delete
self.start_time = time.time()
[483] Fix | Delete
if countcallers:
[484] Fix | Delete
self.globaltrace = self.globaltrace_trackcallers
[485] Fix | Delete
elif countfuncs:
[486] Fix | Delete
self.globaltrace = self.globaltrace_countfuncs
[487] Fix | Delete
elif trace and count:
[488] Fix | Delete
self.globaltrace = self.globaltrace_lt
[489] Fix | Delete
self.localtrace = self.localtrace_trace_and_count
[490] Fix | Delete
elif trace:
[491] Fix | Delete
self.globaltrace = self.globaltrace_lt
[492] Fix | Delete
self.localtrace = self.localtrace_trace
[493] Fix | Delete
elif count:
[494] Fix | Delete
self.globaltrace = self.globaltrace_lt
[495] Fix | Delete
self.localtrace = self.localtrace_count
[496] Fix | Delete
else:
[497] Fix | Delete
# Ahem -- do nothing? Okay.
[498] Fix | Delete
self.donothing = 1
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function