Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """\ |
| 4 | This script prints out a list of undocumented symbols found in |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 5 | Python include files, prefixed by their tag kind. |
| 6 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 7 | Pass Python's include files to ctags, parse the output into a |
| 8 | dictionary mapping symbol names to tag kinds. |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 9 | |
| 10 | Then, the .tex files from Python docs are read into a giant string. |
| 11 | |
| 12 | Finally all symbols not found in the docs are written to standard |
| 13 | output, prefixed with their tag kind. |
| 14 | """ |
| 15 | |
| 16 | # Which kind of tags do we need? |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 17 | TAG_KINDS = "dpst" |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 18 | |
| 19 | # Doc sections to use |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 20 | DOCSECTIONS = ["api"]# ["api", "ext"] |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 21 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 22 | # Only print symbols starting with this prefix, |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 23 | # to get all symbols, use an empty string |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 24 | PREFIXES = ("Py", "PY") |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 25 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 26 | INCLUDEPATTERN = "*.h" |
| 27 | |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 28 | # end of customization section |
| 29 | |
| 30 | |
| 31 | # Tested with EXUBERANT CTAGS |
| 32 | # see http://ctags.sourceforge.net |
| 33 | # |
| 34 | # ctags fields are separated by tabs. |
| 35 | # The first field is the name, the last field the type: |
| 36 | # d macro definitions (and #undef names) |
| 37 | # e enumerators |
| 38 | # f function definitions |
| 39 | # g enumeration names |
| 40 | # m class, struct, or union members |
| 41 | # n namespaces |
| 42 | # p function prototypes and declarations |
| 43 | # s structure names |
| 44 | # t typedefs |
| 45 | # u union names |
| 46 | # v variable definitions |
| 47 | # x extern and forward variable declarations |
| 48 | |
| 49 | import os, glob, re, sys, tempfile |
| 50 | |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 51 | def findnames(file, prefixes=()): |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 52 | names = {} |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 53 | for line in file.xreadlines(): |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 54 | if line[0] == '!': |
| 55 | continue |
| 56 | fields = line.split() |
| 57 | name, tag = fields[0], fields[-1] |
| 58 | if tag == 'd' and name.endswith('_H'): |
| 59 | continue |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 60 | if prefixes: |
| 61 | sw = name.startswith |
| 62 | for prefix in prefixes: |
| 63 | if sw(prefix): |
| 64 | names[name] = tag |
| 65 | else: |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 66 | names[name] = tag |
| 67 | return names |
| 68 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 69 | def print_undoc_symbols(prefix, docdir, incdir): |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 70 | docs = [] |
| 71 | |
| 72 | for sect in DOCSECTIONS: |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 73 | for file in glob.glob(os.path.join(docdir, sect, "*.tex")): |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 74 | docs.append(open(file).read()) |
| 75 | |
| 76 | docs = "\n".join(docs) |
| 77 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 78 | incfiles = os.path.join(incdir, INCLUDEPATTERN) |
| 79 | |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 80 | fp = os.popen("ctags -IDL_IMPORT --c-types=%s -f - %s" |
| 81 | % (TAG_KINDS, incfiles)) |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 82 | dict = findnames(fp, prefix) |
| 83 | names = dict.keys() |
| 84 | names.sort() |
| 85 | for name in names: |
| 86 | if docs.find(name) == -1: |
| 87 | print dict[name], name |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 88 | |
| 89 | if __name__ == '__main__': |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 90 | srcdir = os.path.dirname(sys.argv[0]) |
| 91 | incdir = os.path.normpath(os.path.join(srcdir, "../../Include")) |
| 92 | docdir = os.path.normpath(os.path.join(srcdir, "..")) |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 93 | |
Fred Drake | ea4d2c0 | 2001-11-29 04:30:46 +0000 | [diff] [blame] | 94 | print_undoc_symbols(PREFIXES, docdir, incdir) |