ยปCore Development>Code coverage>Tools/scripts/eptags.py

Python code coverage for Tools/scripts/eptags.py

#countcontent
1n/a#! /usr/bin/env python3
2n/a"""Create a TAGS file for Python programs, usable with GNU Emacs.
3n/a
4n/ausage: eptags pyfiles...
5n/a
6n/aThe output TAGS file is usable with Emacs version 18, 19, 20.
7n/aTagged are:
8n/a - functions (even inside other defs or classes)
9n/a - classes
10n/a
11n/aeptags warns about files it cannot open.
12n/aeptags will not give warnings about duplicate tags.
13n/a
14n/aBUGS:
15n/a Because of tag duplication (methods with the same name in different
16n/a classes), TAGS files are not very useful for most object-oriented
17n/a python projects.
18n/a"""
19n/aimport sys,re
20n/a
21n/aexpr = r'^[ \t]*(def|class)[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*[:\(]'
22n/amatcher = re.compile(expr)
23n/a
24n/adef treat_file(filename, outfp):
25n/a """Append tags found in file named 'filename' to the open file 'outfp'"""
26n/a try:
27n/a fp = open(filename, 'r')
28n/a except OSError:
29n/a sys.stderr.write('Cannot open %s\n'%filename)
30n/a return
31n/a charno = 0
32n/a lineno = 0
33n/a tags = []
34n/a size = 0
35n/a while 1:
36n/a line = fp.readline()
37n/a if not line:
38n/a break
39n/a lineno = lineno + 1
40n/a m = matcher.search(line)
41n/a if m:
42n/a tag = m.group(0) + '\177%d,%d\n' % (lineno, charno)
43n/a tags.append(tag)
44n/a size = size + len(tag)
45n/a charno = charno + len(line)
46n/a outfp.write('\f\n%s,%d\n' % (filename,size))
47n/a for tag in tags:
48n/a outfp.write(tag)
49n/a
50n/adef main():
51n/a outfp = open('TAGS', 'w')
52n/a for filename in sys.argv[1:]:
53n/a treat_file(filename, outfp)
54n/a
55n/aif __name__=="__main__":
56n/a main()