source: vendor/python/2.5/Doc/tools/custlib.py

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.1 KB
Line 
1# Generate custlib.tex, which is a site-specific library document.
2
3# Phase I: list all the things that can be imported
4
5import glob
6import os.path
7import sys
8
9modules = {}
10
11for modname in sys.builtin_module_names:
12 modules[modname] = modname
13
14for dir in sys.path:
15 # Look for *.py files
16 filelist = glob.glob(os.path.join(dir, '*.py'))
17 for file in filelist:
18 path, file = os.path.split(file)
19 base, ext = os.path.splitext(file)
20 modules[base.lower()] = base
21
22 # Look for shared library files
23 filelist = (glob.glob(os.path.join(dir, '*.so')) +
24 glob.glob(os.path.join(dir, '*.sl')) +
25 glob.glob(os.path.join(dir, '*.o')) )
26 for file in filelist:
27 path, file = os.path.split(file)
28 base, ext = os.path.splitext(file)
29 if base[-6:] == 'module':
30 base = base[:-6]
31 modules[base.lower()] = base
32
33# Minor oddity: the types module is documented in libtypes2.tex
34if modules.has_key('types'):
35 del modules['types']
36 modules['types2'] = None
37
38# Phase II: find all documentation files (lib*.tex)
39# and eliminate modules that don't have one.
40
41docs = {}
42filelist = glob.glob('lib*.tex')
43for file in filelist:
44 modname = file[3:-4]
45 docs[modname] = modname
46
47mlist = modules.keys()
48mlist = filter(lambda x, docs=docs: docs.has_key(x), mlist)
49mlist.sort()
50mlist = map(lambda x, docs=docs: docs[x], mlist)
51
52modules = mlist
53
54# Phase III: write custlib.tex
55
56# Write the boilerplate
57# XXX should be fancied up.
58print """\documentstyle[twoside,11pt,myformat]{report}
59\\title{Python Library Reference}
60\\input{boilerplate}
61\\makeindex % tell \\index to actually write the .idx file
62\\begin{document}
63\\pagenumbering{roman}
64\\maketitle
65\\input{copyright}
66\\begin{abstract}
67\\noindent This is a customized version of the Python Library Reference.
68\\end{abstract}
69\\pagebreak
70{\\parskip = 0mm \\tableofcontents}
71\\pagebreak\\pagenumbering{arabic}"""
72
73for modname in mlist:
74 print "\\input{lib%s}" % (modname,)
75
76# Write the end
77print """\\input{custlib.ind} % Index
78\\end{document}"""
Note: See TracBrowser for help on using the repository browser.