]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Tools/scripts/ptags.py
AppPkg/Applications/Python: Add Python 2.7.2 sources since the release of Python...
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / scripts / ptags.py
CommitLineData
4710c53d 1#! /usr/bin/env python\r
2\r
3# ptags\r
4#\r
5# Create a tags file for Python programs, usable with vi.\r
6# Tagged are:\r
7# - functions (even inside other defs or classes)\r
8# - classes\r
9# - filenames\r
10# Warns about files it cannot open.\r
11# No warnings about duplicate tags.\r
12\r
13import sys, re, os\r
14\r
15tags = [] # Modified global variable!\r
16\r
17def main():\r
18 args = sys.argv[1:]\r
19 for filename in args:\r
20 treat_file(filename)\r
21 if tags:\r
22 fp = open('tags', 'w')\r
23 tags.sort()\r
24 for s in tags: fp.write(s)\r
25\r
26\r
27expr = '^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*[:\(]'\r
28matcher = re.compile(expr)\r
29\r
30def treat_file(filename):\r
31 try:\r
32 fp = open(filename, 'r')\r
33 except:\r
34 sys.stderr.write('Cannot open %s\n' % filename)\r
35 return\r
36 base = os.path.basename(filename)\r
37 if base[-3:] == '.py':\r
38 base = base[:-3]\r
39 s = base + '\t' + filename + '\t' + '1\n'\r
40 tags.append(s)\r
41 while 1:\r
42 line = fp.readline()\r
43 if not line:\r
44 break\r
45 m = matcher.match(line)\r
46 if m:\r
47 content = m.group(0)\r
48 name = m.group(2)\r
49 s = name + '\t' + filename + '\t/^' + content + '/\n'\r
50 tags.append(s)\r
51\r
52if __name__ == '__main__':\r
53 main()\r