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