blob: 9958451c70f3958e9f5e38f5fb38108fb507deb8 [file] [log] [blame]
Guido van Rossum6cb2ac21997-06-02 17:57:10 +00001# 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, os, sys, string
6modules={}
7
8for modname in sys.builtin_module_names:
9 modules[modname]=modname
10
11for dir in sys.path:
12 # Look for *.py files
13 filelist=glob.glob(os.path.join(dir, '*.py'))
14 for file in filelist:
Fred Drake77878412000-10-07 12:50:05 +000015 path, file = os.path.split(file)
16 base, ext=os.path.splitext(file)
17 modules[string.lower(base)]=base
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000018
19 # Look for shared library files
20 filelist=(glob.glob(os.path.join(dir, '*.so')) +
Fred Drake77878412000-10-07 12:50:05 +000021 glob.glob(os.path.join(dir, '*.sl')) +
22 glob.glob(os.path.join(dir, '*.o')) )
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000023 for file in filelist:
Fred Drake77878412000-10-07 12:50:05 +000024 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
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000028
29# Minor oddity: the types module is documented in libtypes2.tex
30if modules.has_key('types'):
31 del modules['types'] ; modules['types2']=None
32
33# Phase II: find all documentation files (lib*.tex)
34# and eliminate modules that don't have one.
35
36docs={}
37filelist=glob.glob('lib*.tex')
38for file in filelist:
39 modname=file[3:-4]
40 docs[modname]=modname
41
42mlist=modules.keys()
43mlist=filter(lambda x, docs=docs: docs.has_key(x), mlist)
44mlist.sort()
45mlist=map(lambda x, docs=docs: docs[x], mlist)
46
47modules=mlist
48
49# Phase III: write custlib.tex
50
51# Write the boilerplate
52# XXX should be fancied up.
53print """\documentstyle[twoside,11pt,myformat]{report}
54\\title{Python Library Reference}
55\\input{boilerplate}
Fred Drake77878412000-10-07 12:50:05 +000056\\makeindex % tell \\index to actually write the .idx file
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000057\\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}"""
67
68for modname in mlist:
69 print "\\input{lib%s}" % (modname,)
70
71# Write the end
Fred Drake77878412000-10-07 12:50:05 +000072print """\\input{custlib.ind} % Index
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000073\\end{document}"""